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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
liyucao
Employee
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
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.