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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jay13
Regular 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.

IDcode
1M
1D
1L
2D
2M
3D
2 ACCEPTED SOLUTIONS
Gabry
Super User
Super User

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 works

View solution in original post

Simple enough,

ThxAlot_0-1726772312651.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

9 REPLIES 9
SachinNandanwar
Super User
Super User

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])

 



Regards,
Sachin
Check out my Blog
Gabry
Super User
Super User

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 works
jay13
Regular 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. 

IDcode
1M
1D
1L
2D
2M
3D
4D
5D

Simple enough,

ThxAlot_0-1726772312651.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Thank you @ThxAlot this one works as well!

You're right. I changed the previous post with the updated formula. Let me know

jay13
Regular Visitor

Thanks @Gabry ! Are you able to explain how this is working? I am understanding pieces of it but when we get to the last filter where its <> "D" then =0 I am getting a little lost. I really appriciate the help on this one. Thanks again!

Yeah, sure, I can try. You can use the DAX query view to help debug the code.

This part of the code:
FILTER (
VALUES ( Tabella[ID] ),
CALCULATE ( COUNTROWS ( FILTER ( Tabella, Tabella[code] <> "D" ) ) ) = 0
)

filters out all the IDs that have a code different from "D". It essentially says to keep only the rows where the count is 0.

Then, you just count the IDs in this filtered table with:

 

DISTINCTCOUNT ( Tabella[ID] )

 

and you'll get the number of IDs.

😉

jay13
Regular Visitor

Thanks so much for the help!

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.

Top Solution Authors
Top Kudoed Authors