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
mohsenvafa
Helper I
Helper I

DAX Record Count - One to Many

Hi

 

I am new to Power BI and DAX, I need help to write a query for my report. Can someone help me on this, please.

 

In my data model I have one to many relationship between two tables, Reviews and ReviewResponse. I would like to add a column in Reviews table to show True if there is any related record found in ReviewResponse or False if there is not. I addition, I want to count number of responses for each review. If there is no response, I expect to have 0 for thoese records. DISTINCTCOUNT(ReviewResponse[Id]) will work fine but it filters out reviews which doesn't have any responses. 
What is the right way to do this?

question.png

2 REPLIES 2
AlexChen
Microsoft Employee
Microsoft Employee

Hi mohsenvafa,

 

For example, you have 2 table Review/ReviewResponse like below. They connected by Review[id] and ReviewResponse[reviewId].

 

Review:

1.png

 

ReviewResponse:

2.png

 

To show if the review have response or not, you can use RELATEDTABLE() to filter the responses. Please add a column like below:

 

hasanswer = if(countax(RELATEDTABLE(ReviewResponse), ReviewResponse[reviewId] = Reviews[id]) > 0, TRUE(), FALSE())

 

To show count of response you can use following DAX:

 

countOfResponse = if(countax(RELATEDTABLE(ReviewResponse), ReviewResponse[reviewId] = Reviews[id]) = BLANK(), 0, countax(RELATEDTABLE(ReviewResponse), ReviewResponse[reviewId] = Reviews[id]))

 

This is the result for Review Table:

3.png

 

Best Regards

Alex

 

ankitpatira
Community Champion
Community Champion

@mohsenvafa Create calculated column using below DAX,

 

CalculatedColumn = 

IF( CALCULATE(COUNTROWS(ReviewResponses), FILTER( ReviewResponses, ReviewResponses[ReviewID] = EARLIER(Reviews[ID] ))) > 0, "True", "False")

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.