Forum Discussion

Jtbonner1986's avatar
Jtbonner1986
Icon for Helper I rankHelper I
1 year ago
Solved

Count Non Matching Rows

Hi, 

 

Sorry for the basic question here:

I have 2 tables, a pricing table and a material table (joined by material ID). I want to understand where i have a record in my material table but do not have a price for it. I basically want to count the non matching rows in the pricing table when i plot my material table:

 

EG:

 

Material Table

 

MaterialProduct
1231
3451
6781

 

Pricing Table:

 

MaterialPrice
123£100
XXX£50

 

I want a measure to return a count of '2' when i select Product '1'

  • Hi Jtbonner1986 

     

    Create a one-to-many single direciton relationship from Price to Material

    Create this measure:

    count = 
    CALCULATE (
        COUNTROWS ( Material ),
        KEEPFILTERS ( ISBLANK ( 'Price'[Material] ) )
    )
    

     

8 Replies

  • Please share more information, I am not clear what you are expecting in result.

    • Jtbonner1986's avatar
      Jtbonner1986
      Icon for Helper I rankHelper I

      i want a single card visual displaying the number of materials which do not have a price. in this case material 345 and 678 do not have prices so i would want the result 2

  • Jtbonner1986 

    Create a relationship between the Material Table and the Pricing Table using the Material column.

    Create a measure in your Material Table to count the non-matching rows

    DAX
    NonMatchingCount =
    CALCULATE(
    COUNTROWS('Material Table'),
    ISBLANK(RELATED('Pricing Table'[Price]))
    )

     

  • Hi Jtbonner1986 

     

    Create a one-to-many single direciton relationship from Price to Material

    Create this measure:

    count = 
    CALCULATE (
        COUNTROWS ( Material ),
        KEEPFILTERS ( ISBLANK ( 'Price'[Material] ) )
    )
    

     

    • Jtbonner1986's avatar
      Jtbonner1986
      Icon for Helper I rankHelper I

      I want to add a layer of complexity to this... So my price table can have multiple rows in it (for differing prices & dates) 

       

      I want to essentially do the same (count the blank rows) however, due to the natrue of this structure it now returns '3'

       

      new Price Table:

       

      MaterialPriceDate
      123£10001/01/2024
      XXX£1001/01/2024
      123£5002/01/2024

       

      • danextian's avatar
        danextian
        Icon for Super User rankSuper User

        Hi Jtbonner1986 

        Break the relationship between the two tables and try this:

        non matching materials = 
        COUNTROWS (
            -- EXCEPT returns the set of values in 'Material[Material]' that are not in 'Price[Material]'
            EXCEPT ( VALUES ( Material[Material] ), VALUES ( 'Price'[Material] ) ) 
        )