Forum Discussion

darpao's avatar
darpao
New Member
5 years ago
Solved

Multiple response and filters

I have a survey that generate 2 tables, one main table like this (Main):

 

IDYearCountry
12018UK
22019USA
32019USA
42020Germany
52020USA
62018Germany

 

and another derived from a multiple response like this (Tecahnology):

 

IDTechnology
1A
1B
2B
3A
3C
3D
4C
5B
5C
5D
6A

 

Now in a page I have 3 filters, one compulsory and another 2 optionals:

 

technology - must be A, B, C, or D (only one of this, single choice)

year - could be void or could be one or more out of 2018, 2019, 2020

country - like year, is not necessary to get it

 

and I want a summary table with this data:

 

Filter on A

 

YearPercentage
2018=2/2 -> 100% because both 1 and 6 have technology A
2019=1/2 -> 50% because only 3 has technology A and not 2
2020=0/2 -> 0% because neither 4 or 5 have technology A

 

I'm not able to get the 2 of the denominator. I have tried CALCULATE with COUNTROWS, ALLSELECTED, ALLCROSSFILTER and so on, but nothing.

 

When then I filter also, for example country USA, the table should update like this:

 

Filter on A and USA

 

YearPercentage
2018=0/0 -> 0% because both 1 and 6 are not in USA
2019=1/2 -> 50% it remains like the previous table, because both 2 and 3 are in USA
2020=0/1 -> 0% denominator change to 1 because only 5 is in USA

 

 

Any helps?

I'm stucked with it from days.

 

Thank you

  • Finally I was able to find the solution.

    Thank you ERD because your code helped me.

     

    This is what I was looking for:

     

    #Percentage = VAR main_id = CALCULATE(COUNTROWS('T-main'),REMOVEFILTERS('T-tech'[Technology]))
    VAR tech_id = COUNT('T-tech'[ID])
    VAR percentage = tech_id / main_id
    RETURN
    COALESCE(percentage,0)

4 Replies

  • ERD's avatar
    ERD
    Icon for Community Champion rankCommunity Champion

    Hi darpao ,

    I suppose your tables are connected via ID column. You can try this measure:

    #Percentage = 
    VAR main_id = COUNT('T-main'[ID])
    VAR tech_id = CALCULATE(COUNT('T-tech'[ID]))
    VAR percentage = tech_id / main_id
    RETURN 
    COALESCE(percentage,0)

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

    • darpao's avatar
      darpao
      New Member

      Thank you ERD ,

      I still get all 1 in the table, like dividing the same amount.

      Did you forget the second argument of calculate function in tech_id variable, maybe?

       

      Can you attach the PBIX attemps that you did?

      • ERD's avatar
        ERD
        Icon for Community Champion rankCommunity Champion

        darpao ,

        I'm not sure what do you mean. You can check what you get by separating the measure:

        #tech_id = CALCULATE(COUNT('T-tech'[ID]))
        #main_id = COUNT('T-main'[ID])

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