Forum Discussion

AishwaryaP_'s avatar
AishwaryaP_
Regular Visitor
4 years ago
Solved

Count with multiple conditions

Q1_AQ1_BQ1_CQ1_DState
45221
24112
32252
35331
35241
21521
31451
12152
23531

 

I want to calculate count of 4 from Q1_A, Q1_B, Q1_C, Q1_D for State= 1 and want to calculate % of Count of 4/count State =1 

The answer should be,

Count of 4 for State 1= 3, 

Total count of state 1 = 6 , % = 50% 

 

Need help in writing a measure. 

  • AishwaryaP_ 

    add an index colomn and select index and state column to unpivot other columns.

    Then create a measure

    measure = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[State]=1 && 'Table'[Value]=4))
    /CALCULATE(DISTINCTCOUNT('Table'[Index]),FILTER('Table','Table'[State]=1))

    pls see the attachment below

2 Replies

  • AishwaryaP_ 

    add an index colomn and select index and state column to unpivot other columns.

    Then create a measure

    measure = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[State]=1 && 'Table'[Value]=4))
    /CALCULATE(DISTINCTCOUNT('Table'[Index]),FILTER('Table','Table'[State]=1))

    pls see the attachment below

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi AishwaryaP_ 

     

    If you don't want to change the table format, then try this one

    count = 
    VAR T1=FILTER('Table','Table'[State]=1)
    RETURN
    COUNTROWS(FILTER(T1, 4 IN {[Q1_A],[Q1_B],[Q1_C],[Q1_D]}))
    
    count% = 
    VAR T1=FILTER('Table','Table'[State]=1)
    RETURN
    [count]/COUNTROWS(T1)