Forum Discussion

pbhat89's avatar
pbhat89
Icon for Helper II rankHelper II
5 years ago
Solved

Cross filtering across tables

My one table is given in the format below 

ID Age Height Score

1   20     167     120

2   30     150     122

3   40     190      100

 

Table 2 is 

ID Condition

1    A

1    A

2    B

3    C

 

Now i have joined the two tables as one to many join (tab 1 to Tab 2) . In dashboard i want the filter (in addition to other filters) to be :

 

Drop downlist of - all selected originally

A

B

C

 

Measure_C = count(ID) = 3

Now filter out (unselect) condition A from table 2 , Measure_C now = 2 ( as ID 1 gets dropped )

 

How do i achieve this ? i have selected one-to-many join and apply filters both directions - but doesn't work. i want it to only apply on table 1. Note i need unselecting - not selecting i.e. if i click on A from drop down - measure = 1 ( as ID 1 is only counted ) . This is where i am currently. Appreciate your help.

  • Hi pbhat89 ,

     

    Do you want the result is the measure or the table?

    If the measure is your result, please refer the following steps.

     

    1. Change the Both direction to Single.

     

     

    2. Then create a measure like this,

     

    Measure = 
    var _selected = SELECTEDVALUE('Table 2'[Condition])
    var _select_count = CALCULATE(COUNT('Table 1'[ID]),FILTER('Table 2','Table 2'[Condition]=_selected))
    var _Total = COUNT('Table 1'[ID])
    return
    _Total - _select_count
    

     

     

     

    If you have any question, please kindly ask here and we will try to resolve it.

     

    Best regards,

     

    Community Support Team _ zhenbw

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    BTW, pbix as attached.

8 Replies

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion
    Do you need Table1 for anything?

    Can you try Measure_C = DISTINCTCOUNT(Table2[ID])
    • pbhat89's avatar
      pbhat89
      Icon for Helper II rankHelper II

      Table 1 is actually the main table for me to do the counts.

      For e.g. my filters are :

       

      Age < 35 

      measure_C = 2 ( ID 1 , 2)

       

      filter out (unselect) condition A 

      measure_C= 1 ( ID 2 ) 

       

      Basically i want to filter to work oppsite i.e. when i select the conditions from a list , it should remove the corresponding IDs from the main table. As a default it should have everything to start. 

      • AllisonKennedy's avatar
        AllisonKennedy
        Icon for Community Champion rankCommunity Champion
        It would be easier just to change the selection controls on the slicer, and turn off single select with ctrl and adjust a few other things to get it how you want.

        If you absolutely need to restrict them to a single item to exclude, then you will need to create a slicer table that is NOT related to the data so that when you select an item other items are still visible;
        Create a NEW TABLE:
        Slicer = VALUES(table[item])

        Then you'll need to create a measure, possibly using:

        Items to show = IF(SELECTEDVALUE(table[Item]) NOT IN Values(slicer[item]), "Yes", "No")

        Finally, use that measure to filter the visuals.
  • v-zhenbw-msft's avatar
    v-zhenbw-msft
    Icon for Community Support rankCommunity Support

    Hi pbhat89 ,

     

    If you have to use the Table 1[ID], maybe you can try to change the relationship direction to Both.

     

     

     

     

    If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

     

    Best regards,

     

    Community Support Team _ zhenbw

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    BTW, pbix as attached.

    • pbhat89's avatar
      pbhat89
      Icon for Helper II rankHelper II

      I understand the example given by me may not be really representative. So updating the example and sharing expected output of the table and a measure. 

       

      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.  

       

      The current join is in BOTH direction and via ID 

       

      FILTERS & MEASURE - EXPECTED OUTPUT.

      FILTER 1 = AGE < 35 

      FILTER 2 = EXCLUDE (not filter on) IDs with CONDITION (A)

       

      TABLE 1 after filters 

      Measure : Count_of_unique_ID = 4

       

      Right now the filter 2 above - filters on i.e. selects the IDs where A happened where as i want to remove the IDs where A happened. and then update the measure Count_of_unique_ID

       

      Hope the query is clear now?

       

       

       

       

       

       

       

      • v-zhenbw-msft's avatar
        v-zhenbw-msft
        Icon for Community Support rankCommunity Support

        Hi pbhat89 ,

         

        Do you want the result is the measure or the table?

        If the measure is your result, please refer the following steps.

         

        1. Change the Both direction to Single.

         

         

        2. Then create a measure like this,

         

        Measure = 
        var _selected = SELECTEDVALUE('Table 2'[Condition])
        var _select_count = CALCULATE(COUNT('Table 1'[ID]),FILTER('Table 2','Table 2'[Condition]=_selected))
        var _Total = COUNT('Table 1'[ID])
        return
        _Total - _select_count
        

         

         

         

        If you have any question, please kindly ask here and we will try to resolve it.

         

        Best regards,

         

        Community Support Team _ zhenbw

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

         

        BTW, pbix as attached.