Forum Discussion
jay13
1 year agoRegular Visitor
Countrows with filters
I am trying to count the rows for an ID where they only have a specific code.
Example: If I am looking to count the IDs that only have code D how would I count just that row. In this case the count would be 1 because only ID 3 has code D only.
| ID | code |
| 1 | M |
| 1 | D |
| 1 | L |
| 2 | D |
| 2 | M |
| 3 | D |
Hello jay13
this is your measure
ContaSoloD =CALCULATE (DISTINCTCOUNT ( Tabella[ID] ),FILTER (VALUES ( Tabella[ID] ),CALCULATE ( COUNTROWS ( FILTER ( Tabella, Tabella[code] <> "D" ) ) ) = 0))
let me know if it worksSimple enough,
9 Replies
- jay13Regular Visitor
thank you for the reply. This seemed to work at first but if I add additional rows it is still only counting one?
Example: It should count 3 since ID's 3,4 and 5 have code D only.
ID code 1 M 1 D 1 L 2 D 2 M 3 D 4 D 5 D - GabrySuper User
You're right. I changed the previous post with the updated formula. Let me know
- SachinNandanwarImpactful Individual
Just incase if you want to return ID's that only have one instance of "D"
Table_1 = VAR _Table = SUMMARIZE( 'Table', 'Table'[ID], "Codes", DISTINCTCOUNT( ( 'Table'[code] )), "Codes_D",COUNTROWS( FILTER( 'Table', 'Table'[code] = "D" )) ) RETURN FILTER(_Table,[Codes]=[Codes_D])