Forum Discussion

pbhat89's avatar
pbhat89
Helper II
5 years ago
Solved

Cross filter ( to exclude )

I previously raised this query ( https://community.powerbi.com/t5/Desktop/Cross-filtering-across-tables/m-p/1398390# ) and (https://community.powerbi.com/t5/Desktop/Cross-Filter-across-tables-2/m-p/1412162#M597413) but haven't got effective response to close the issue. Reposting with more clarity on the requirement.

 

Restating the example below, with minor edit in filters :

 

TABLE 1

 
 
 

 
 
 

 

 

 

Each row shows 1 ID only. ID does not repeat in TABLE 1

Measure : Count_of_unique_ID = 8

 

TABLE 2 

 

 

Each row is a unique combination of ID and Condition. i.e. ID,condition won't repeat. The table may have <= IDs from table 1. E.g. it will not have a new ID 10 which has not occured in table 1 and it doesn't need to have all IDs as they occur in table 1. Where there was no condition e.g. 4,6,8 , they didn't occur in table 1.   

 

The current join is in BOTH direction and via ID 

 

FILTERS & MEASURE - EXPECTED OUTPUT.

FILTER 1 = AGE < 35 [REMOVE ALL that are above 35]

FILTER 2 = EXCLUDE (not filter on) IDs with CONDITION (A OR B) - two selected [ multiple selection should be allowed here in solution]. All others which do not have condition A or B or any condition ( do not come in table 2 ) should be shown. Where A or B occured ( IDs , should be excluded ) . The filter should work as multi select e.g. (A or B)

TABLE 1 after filters 

 

Measure : Count_of_unique_ID = 3

 

Based on previous solution by (Community Support Team _ zhenbw) in link (https://community.powerbi.com/t5/Desktop/Cross-filtering-across-tables/m-p/1398390#it only works if one condition is selected i.e. A . If i select two conditions, it reverts to its original count. 

 

What is the best appraoch to resolve this?

 

 

9 Replies

  • Hi pbhat89 ,

     

    Based on the data you show you need to do a measure similar to this one:

    Calculation =
    VAR temp_table =
        FILTER (
            ALLSELECTED ( Table1[ID]; Table1[Age] );
            NOT ( Table1[ID] IN VALUES ( Table2[ID] ) )
        )
    RETURN
        COUNTROWS ( temp_table )

     

    Be aware that I'm only working with two slicers on Age and on condition if you want to add additional slicers for height or score you need to add it to the allseleted stament.

     

    Resulta attach and below:

    Be aware that in this option I have turn off the interactions betweent the two slicers but they can be on if you need it.

    • pbhat89's avatar
      pbhat89
      Helper II

      Since in actual case - i have many variables in table 1 which may be used as filters - could you advise something like : 

       

      FILTER(input_db_disc_edited,input_db_disc_edited[name]=_selected)) + the NOT ( table1[ID]....in table2[ID]) 
      • MFelix's avatar
        MFelix
        Super User

        Hi pbhat89 ,

         

        As refered you need to place those variable inside the allselected

         

        Calculation =
        VAR temp_table =
            FILTER (
                ALLSELECTED ( Table1[ID]; Table1[Age]; table [column];...;table [columnzz] );
                NOT ( Table1[ID] IN VALUES ( Table2[ID] ) )
            )
        RETURN
            COUNTROWS ( temp_table )