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
Anonymous
Not applicable

measure that counts matching rows of a column based on the corresponding value of another column

So say i have a table like below:

 

IDIDtype
1A
2A
3B
4C
5D
6E
7F
8G
9G
10G

 

i would like to create an output table as such:

 

IDIDtype count
12
22
31
41
51
61
71
83
93
103

 

i would like to do this as a measure and not calculated column because i need it to update based on slicers. i just can't figure out how to retreive the corresponding "IDtype" for the "type" pivot coordinate using DAX. Any help is much appreciated,

 

thanks!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please try the below measure.

The link to the sample pbix file is down below.

 

ID Type count =
VAR currentIDtype =
MAX ( 'Table'[IDtype] )
VAR newtable =
FILTER ( ALL ( 'Table' ), 'Table'[IDtype] = currentIDtype )
RETURN
COUNTROWS ( newtable )

 

Picture7.png

 

 

https://www.dropbox.com/s/9py88hp4ox188h9/gsingh67.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please try the below measure.

The link to the sample pbix file is down below.

 

ID Type count =
VAR currentIDtype =
MAX ( 'Table'[IDtype] )
VAR newtable =
FILTER ( ALL ( 'Table' ), 'Table'[IDtype] = currentIDtype )
RETURN
COUNTROWS ( newtable )

 

Picture7.png

 

 

https://www.dropbox.com/s/9py88hp4ox188h9/gsingh67.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

thanks, that seems to be working. i just had a follow-up question - i was planning to create a scatter plot ID type count vs costs (costs is a third column i omitted). So i will basically put the measure created above into the x-axis and costs (unsummarised) into the y-axis. this will work except for where there are duplicate costs values (for example if ID1 has the same costs as ID8 then the max() function will only read one of those i believe).

 

are there any alternatives to using max?

Hi,
Thank you for your feedback.

In my measure, what the MAX function does is to fix the current context's result and compare it with all IDs in the table.

I am not 100% sure if I understood your question correctly.

If it is OK with you, please share your sample pbix file, then I can try to come up with a more accurate measure.

 

thank you very much.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

ah ok, thanks for explaining. In that case the issue was that when we filter 'Table'[IDtype] = currentIDtype it returns one match for each ID. This is fine for ID since it is unique. I solved my scatter plot problem by adding ID into the details. Thanks again for your 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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.