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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DataDiva
Helper II
Helper II

Help with calculation

I'm trying to calculate average occupancy rate for a set of hospitals. The formula I have right now is: 

Avg IP Occupancy Rate = 'Calcs'[IP Patient Days]/calculate([Days in Period],ALLSELECTED('vwCHAprimary_Masked'))/AVERAGE('tblFacility'[Licensed Beds])

 

My problem is that the formula doesn't work if I don't put some kind of aggregation on "Licensed Beds" but when I do put an aggreation, it creates a single aggregation for the whole thing, rather than obeying the row context in the table or graph that I put the measure in. In other words, I'm getting:

 

Hospital     Total Patient Days     Days in Period     Licensed Beds    Occupancy Rate

A                 150                             365                         120.5                 wrong

B                  350                            365                         120.5                  wrong

C                  500                            365                         120.5                 wrong

 

What I need is:

Hospital     Total Patient Days     Days in Period     Licensed Beds    Occupancy Rate

A                 150                             365                         100                  Right!

B                  350                            365                         50                     Right!

C                  500                            365                         200                  Right!

 

I have four relevent tables--my Primary table, which feeds the detached "Calcs" table, the facility table, and an extended facility table that is generating the Licensed Beds number within the Facility table. I have two facility tables that share an ID, and then one of those tables (the one in the formula) that share a different facility ID with my primary table. So I used Licensed Beds = related('cha tblFacilityExtended'[Licensed Beds]) to create a column in my Facility table that has licensed beds. Confusing, but I wanted to explain in case that is relevent to my problem. My Primary table contains records of every hospital visit, which is where I can calcuate total Patient Days from. I have a filter to select your time period. And then I have these facility tables that list each facility once, with relevent info about each facility, including licensed beds. 

 

Any idea how to get Power BI to behave the way I need it to...? I'm really confused by the fact that I can put an average of other fields, like Patient Days, and that average will respect the row level context. So why isn't Licensed Beds working that way? I've tried using the original licensed beds field in the extended table, but I tried combining it into the regular facility table because I thought perhaps Power BI didn't know to activate the two-level relationship (Primary-->Facility-->Facility Extended)--In fact, if I add in the Facility ID from the Facility Extended Table, the occupancy rate calc works! But I can't include that in my final table, it's a huge 36 Hex charater tag. I clearly don't understand what Power BI is doing here... 

 

1 ACCEPTED SOLUTION

I figured out the problem! It had to do with having a one-way filter relationship instead of a cross-filter (two-way) relationship. As soon as I fixed that, the measure calculated correctly. Thank you!

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @DataDiva,

 

Based on your description, I have known your desired output.

 

If it is convenient, could you share a dummy pbix file which can reproduce the scenario, so that we can help further investigate on it? You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploading.)

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I figured out the problem! It had to do with having a one-way filter relationship instead of a cross-filter (two-way) relationship. As soon as I fixed that, the measure calculated correctly. Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors