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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

DISTINCTCOUNT with condition

I have data as shown belew 

 

idstagestatus
1acomplete
1bcomplete
1bnot complete
2acomplete
2bnot complete

 

I want to count number of id based on not complete status

so I have apply this Measure:

 

Measure = CALCULATE(
DISTINCTCOUNT(data[id]),FILTER(data,data[status]="not complete"))

 

but as you can see Id 1 have go to stage b tow times one with status complete and the other not complete,

so becouse I am focusing on not complete ids, I do not need to count the id if it on the same stage and with status complete.

 

based on the example the count of not complete will be 2 ,
but i need it to be 1 because i don't need to count id 1 if it is already complete on the same stage

1 ACCEPTED SOLUTION

I think this will work but please test properly with your data:

MeasureX = VAR _tabNot = SUMMARIZECOLUMNS(data[id], data[stage], FILTER(data,data[status] = "not complete"))
           VAR _tabComp = SUMMARIZECOLUMNS(data[id], data[stage], FILTER(data,data[status] = "complete"))
RETURN 
    COUNTROWS(_tabNot) - COUNTROWS(NATURALINNERJOIN(_tabComp, _tabNot))

Each of the variables holds a table with the id and stage of the different statuses.

Count the 'not completed' rows. Subtract from this the count  (of matching id and stage) rows that have a 'complete' and 'not complete'  status.

View solution in original post

7 REPLIES 7
jefe5
New Member

hello, I cant use your solution,,  here is my table, mame Tableau2 

I want to count number CDPs distinct whith contition=Retard, result=2

TI test 

(SUMMARIZECOLUMNS(Tableau2[Nom CDPs],FILTER(Tableau2[Etat])="Retard")))
Nom CDPsEtat
Creation nouveaux bureaux , broyeur, zone decheterieSoldé
Creation nouveaux bureaux , broyeur, zone decheterieSoldé
Creation nouveaux bureaux , broyeur, zone decheterieRetard
Creation nouveaux bureaux , broyeur, zone decheterieRetard
Creation nouveaux bureaux , broyeur, zone decheterieRetard
Creation nouveaux bureaux , broyeur, zone decheterieRetard
nouvelles référencesRetard
nouvelles référencesEn cours
nouvelles référencesEn cours
nouvelles référencesEn cours
t imprimanteSoldé
Greg_Deckler
Community Champion
Community Champion

COUNTROWS(

  SUMMARIZE(

     FILTER(data,data[status]="not complete"),

    [id]

  )

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

thank you 
but it is still the same , i need it first before count to check if the id with same stage have status complete if yes then, do not count it 
if NO, count it.

i need to do this becouse there is a duplicate on id with same stage , so to solve it i have to ignore the id on not complet if it complet with same stage.

hope it is clear

I think this will work but please test properly with your data:

MeasureX = VAR _tabNot = SUMMARIZECOLUMNS(data[id], data[stage], FILTER(data,data[status] = "not complete"))
           VAR _tabComp = SUMMARIZECOLUMNS(data[id], data[stage], FILTER(data,data[status] = "complete"))
RETURN 
    COUNTROWS(_tabNot) - COUNTROWS(NATURALINNERJOIN(_tabComp, _tabNot))

Each of the variables holds a table with the id and stage of the different statuses.

Count the 'not completed' rows. Subtract from this the count  (of matching id and stage) rows that have a 'complete' and 'not complete'  status.

Anonymous
Not applicable

is there any way to return the result as a table?

What would the table look like?

Anonymous
Not applicable

thank you it is working

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.