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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors