Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

DISTINCTCOUNT only on a certain condition

Hello,

 

I need to distinctcount the IDs when the status is only equal to "Pushed" or "Already pushed" (if an ID has a different status, don't count it). Here is a sample table :

IDStatus
1Pushed
2Pushed
2To do

 

The result should be 1 because only one ID has the status exactly equal to "Pushed" or "Already pushed". But my current measure is wrong because it returns 2. My current measure is :

 

CALCULATE(DISTINCTCOUNT 'Fact Assets'[ID]), 'Fact Assets'[Status] IN { "Pushed", "Already pushed" })
 
 

How can I get this measure to return 1 ?

 

Thank you

Best regards

  • Here is one measure expression that should work.

     

    Only Pushed =
    COUNTROWS(
        FILTER(
            VALUES( T3[ID] ),
            ISBLANK(
                CALCULATECOUNT( T3[ID] ), NOT T3[Status] IN { "Pushed", "Already Pushed" } )
            )
        )
    )

     

    Pat

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    Here is one measure expression that should work.

     

    Only Pushed =
    COUNTROWS(
        FILTER(
            VALUES( T3[ID] ),
            ISBLANK(
                CALCULATECOUNT( T3[ID] ), NOT T3[Status] IN { "Pushed", "Already Pushed" } )
            )
        )
    )

     

    Pat

  • Hi,

    Please try the below measure, and check the attached file.

     

     

    expected result: =
    VAR allid =
        VALUES ( 'Fact Assets'[ID] )
    VAR idnotwant =
        CALCULATETABLE (
            VALUES ( 'Fact Assets'[ID] ),
            NOT ( 'Fact Assets'[Status] IN { "Pushed", "Already pushed" } )
        )
    VAR onlyidwant =
        EXCEPT ( allid, idnotwant )
    RETURN
        COUNTROWS ( onlyidwant )