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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Count records in a related table by ID

I have 2 related tables joined on ID. Table1 is a summary table with 1 record per ID and Table2 is a detail table with multiple records per ID. I need a new column in Table1 with a count of records in Table2 that have the same ID. In my example below, I need the formula for the "Record Count" column. Thoughts?

 

Table1

IDRecord Count
1234
4562

 

Table2

IDValue
123asd
123sdf
123dfg
123fgh
456asd
456dfg
1 ACCEPTED SOLUTION
Anonymous
Not applicable

This might work:

 

CALCULATE(COUNTAX(Table2,Table2[Value]),Table2[ID])

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

In Table1, write this calculated column formula

 

=COUNTROWS(RELATEDTABLE(Table2))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

This might work:

 

CALCULATE(COUNTAX(Table2,Table2[Value]),Table2[ID])
Anonymous
Not applicable

Perfect, thanks!

Hi @Anonymous,

 

I realize that this is solved, however why do you need a new column when you can use a measure like,

count = countrows('table2') 

this approach keeps you model leaner and does not require additional work while refreshing.

 

Richard



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


Anonymous
Not applicable

Thanks for the reply. While this works well for grid and chart values, a measure can't be used in slicers and filters. Something that I didn't specify in my post is that I need to be able to filter records where count>X. Otherwise, I like this solution for other applications. Thanks!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.