Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Filter table to show only records which apply to all conditions


I have a table and I want to return all the products which have not been classified as RANGED during that campaign period. So if I filtered on Campaign A it will only return the products that have never ever been ranged so it will only return Grapes.

So it will look at each filtered row and for each product check whether the range is equal to NO

Campaign              Product       Range          
A                      Apple         YES            
A                      Banana        NO
A                      Banana        NO
A                      Banana        YES
A                      Grapes        NO
A                      Grapes        NO

How would I go about creating such table using DAX?

I have tried using filter but this will return the rows which have the range NO rather than returning only the products for that specific campaign where every row of that product has not been ranged.

Current Output:

Banana
Grapes

Expected Output:

Grapes

Solution

  • Table 2 = 
    VAR t =
        ADDCOLUMNS(
        SUMMARIZE('Table', 'Table'[Campaign], 'Table'[Product]),
        "@x", CALCULATE(COUNT('Table'[Range]), 'Table'[Range] = "Yes"
            )
        )
    
    RETURN SELECTCOLUMNS( FILTER(t, [@x] = BLANK()), "Product", 'Table'[Product])
        
    

    enter image description here