Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Count Based on two columns

Hello,

I have a Table,

 

N_NameO_NameO_StatuspatID
AO1Completed8652
AO1Completed8652
AO1Completed8652
AO1Completed8718
AO1Completed8718
AO1Completed8718
AO2Completed 
AO2Completed 
AO2Completed 
AO3New 
AO4In Progress 
AO4In Progress 
BO5Completed8126
BO5Completed8126
BO5Completed8126
BO5Completed8126
BO5Completed8126
BO5New 

 

I wanted produce a table visualization which looks like the below,

 

 

I wrote a dax query, 

count =  IF(ISNUMBER(DISTINCTCOUNT('Table'[PATID])),DISTINCTCOUNT('Table'[PATID]), 0)

 

But this produces a table like counting the null values of patID to be 1,

 

Please help with correct dax query to avoid the above null values.

 

Thanks

 

 

 

  • Hi,

    This measure works

    Count = coalesce(CALCULATE(DISTINCTCOUNT(Data[patID]),Data[patID]<>blank()),0)

    Hope this helps.

  • Why have you used the ALL function there?  Try this measure

    x_Applications Acted Upon = CALCULATE(DISTINCTCOUNT('Left Join'[LOANS.PAT_ID]), 'Left Join'[Application Status] == "Acted",'Left Join'[LOANS.PAT_ID]<>BLANK())

4 Replies

  • Hi,

    This measure works

    Count = coalesce(CALCULATE(DISTINCTCOUNT(Data[patID]),Data[patID]<>blank()),0)

    Hope this helps.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sir, a quick question, 

      How do i implement the same (i.e) avoiding the null values 

      if my original dax query is something like the below,

       

      x_Applications Acted Upon = CALCULATE(DISTINCTCOUNT('Left Join'[LOANS.PAT_ID]), FILTER(ALL('Left Join'[Application Status]), 'Left Join'[Application Status] == "Acted"))
      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Why have you used the ALL function there?  Try this measure

        x_Applications Acted Upon = CALCULATE(DISTINCTCOUNT('Left Join'[LOANS.PAT_ID]), 'Left Join'[Application Status] == "Acted",'Left Join'[LOANS.PAT_ID]<>BLANK())

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you so much Sir