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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
liyucao
Microsoft Employee
Microsoft Employee

How to calculate the row count based on the other table

I have 2 tables. One is risks. It has RiskId and ServiceId. Another table is RiskId and JobId, the RiskId can occur multiple times in table2. I want to use ServiceId as slicer and display the RiskId and the count of occurence in table 2. 

measure =
var _sum = CALCULATE(
    COUNTROWS(table_2)
)
RETURN
_sum
 
It can only show the risks that occur in table 2, I want to show all risks with the select service Id no matter if it exists in table2. And if it does not exist in table 2, the number shows 0. How to write the measure?
1 ACCEPTED SOLUTION

Hi @liyucao,

I'm attaching a pbix file with the my solution.
The final result should be this:

_AAndrade_0-1716401135791.png

 







Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

11 REPLIES 11
_AAndrade
Super User
Super User

Hi @liyucao,

I'm assuming that your measure is compute the right numbers when the RiskID exists in table 2. Take this in mind, to shows 0 when RiskID it's not exist in table 2 I only adjust the return to this:

var _sum = CALCULATE(
    COUNTROWS(table_2)
)
RETURN
IF(
  ISBLANK(_sum),
  0,
  _sum
)




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




If so, the slicer will not take affect, it will show all risks

If you can provide a simple pbix or pictures of what you have now and the desired output,I could be more helpful.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




liyucao_0-1716191278571.png

for example, I want to show the list of risks and count the linked experiment in a time period and show it. Actually there are 8 risks in the service I select, since 3 of 8 have no experiment so it does not show in the table.

But if I add the if condition here. The slicer does not take affect and the table shows all risks. It is very wierd.

liyucao_1-1716191388113.png

 

On the return, replace 0 to BLANK() and see what happens.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




how to make the table contains 8 risks (of the service in the slicer) and show 0 if there is no existing experiment

Without analysing your file, I can't help you further. If you can share a sample pbix file with your example I will take a look otherwise it's a waste of time for both of us.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




https://microsoftapc-my.sharepoint.com/:u:/g/personal/liyucao_microsoft_com/EVc0bLO3RQlAvSdTnB6rYoIB... can you view it?

As expected, the table should show all risks in serviceId A, which is 1,3,4. But the 2 method I try does not show correctly.

liyucao_0-1716199635771.png

 

Hi @liyucao,

I'm attaching a pbix file with the my solution.
The final result should be this:

_AAndrade_0-1716401135791.png

 







Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thanks, it really helps. I am trying to understand the measure.

It will still show the 5 risks that exists in experiment table.

liyucao_0-1716197320343.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors