Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
anoonymous
Helper I
Helper I

Count every single ID if status is only green

Hello guys,

 

I am trying to count every single ID where status is only green.

Based on screenshot the solution should be: 3 (ID:1 + ID:2 + ID:2) Every other ID can't be count in since there is one status = red.

anoonymous_0-1668964333659.png

Can anybody help me ? 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

If you want to count the Unique Ids where the status is only green you can use the following:

 

Green IDs =
VAR _green =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( 'Status table', 'Status table'[Status] = "green" )
    ) //Returns a table of ID values whose status = "green"
VAR _NotGreen =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( ALL ( 'Status table' ), 'Status table'[Status] <> "green" )
    ) //Returns a table of ID Values whose status is not/also not green
RETURN
    COUNTROWS ( EXCEPT ( _green, _NotGreen ) )
//Except returns a table of IDs in which the ID values from the table returned by _NotGreen are excluded from the ID values returned by the _green table.

 

If, however, you want to count the rows for the IDs with only a green status you can use:

 

Green Id rows =
VAR _green =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( 'Status table', 'Status table'[Status] = "green" )
    )
VAR _NotGreen =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( ALL ( 'Status table' ), 'Status table'[Status] <> "green" )
    )
RETURN
    COUNTROWS ( CALCULATETABLE ( 'Status table', EXCEPT ( _green, _NotGreen ) ) )
//The same as the previous calculation, but counts the ROWS OF THE WHOLE TABLE (not only IDs) for IDs with only a status of = "green"

 

unique green.jpggreen result.jpg





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1668981891569.png

 

For fun only, a showcase of powerful Excel worksheet formulas

CNENFRNL_1-1668981990028.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

PaulDBrown
Community Champion
Community Champion

If you want to count the Unique Ids where the status is only green you can use the following:

 

Green IDs =
VAR _green =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( 'Status table', 'Status table'[Status] = "green" )
    ) //Returns a table of ID values whose status = "green"
VAR _NotGreen =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( ALL ( 'Status table' ), 'Status table'[Status] <> "green" )
    ) //Returns a table of ID Values whose status is not/also not green
RETURN
    COUNTROWS ( EXCEPT ( _green, _NotGreen ) )
//Except returns a table of IDs in which the ID values from the table returned by _NotGreen are excluded from the ID values returned by the _green table.

 

If, however, you want to count the rows for the IDs with only a green status you can use:

 

Green Id rows =
VAR _green =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( 'Status table', 'Status table'[Status] = "green" )
    )
VAR _NotGreen =
    CALCULATETABLE (
        VALUES ( 'Status table'[ID] ),
        FILTER ( ALL ( 'Status table' ), 'Status table'[Status] <> "green" )
    )
RETURN
    COUNTROWS ( CALCULATETABLE ( 'Status table', EXCEPT ( _green, _NotGreen ) ) )
//The same as the previous calculation, but counts the ROWS OF THE WHOLE TABLE (not only IDs) for IDs with only a status of = "green"

 

unique green.jpggreen result.jpg





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.