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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
BlueTeam
Helper II
Helper II

Count Rows from Related Table with Filters

Been away from PowerBI for a few years and trying to get back into it but having a challenge with a relatively easy calculation.

 

I have two tables "Person" and "History" with a one-to-many relationship via the "PersonID".  I've been unsucessful in calculating the percent of person who have a status of "H" from the "Person" table.  I've used the below function with a filter but that returns the total count from the table, not just the realated records from "History".

 

This is what I've used and now I'm thinking I need to somehow set 'Person'[PersonID] = 'History'[PersonID]

COUNTROWS(FILTER(Person, Person[Status]="Y"))
 
Not sure why the realationship in the model is not restricting the counts but anyone's help here would be greatly appreciated.
 
Thanks in advance!
 
Tim
2 REPLIES 2
BlueTeam
Helper II
Helper II

I finally got something working but it is likely not the most efficient.  I know I calculated various percentages from related tables for Cards in the past and don't remember doing them this way.  Here is the DAX I used:

 
MEASURE =
CALCULATE(
    DIVIDE(
COUNTROWS(FILTER('PERSON', CONTAINS(HISTORY,[PersonID]'PERSON'[PersonId]) && PERSON[Indicator]="Y"))
,
COUNTROWS(FILTER('PERSON', CONTAINS(HISTORY,[PersonID]'PERSON'[PersonId])
))))

Hi,

Share data in a format that can be pasted in an MS Excel file and show the expected result clearly.


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

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.