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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Percentage Measure on Card Visual - Incorrect Calculation across Dates

Does anyone know how I could get a card visual to change dynamically based on the year and month selected on two slicers?

 

For my card visual, I'm currently using this formula: 

Occupancy % = 1 - (DIVIDE([Vacancies],[Total Units])), where my [Vacancies] and [Total Units] are two separate measures.

 

  • Vacancies = CALCULATE(COUNTROWS(TenantsTable),TenantsTable[Status]="Vacant")
  • Total Units = SUM(HomesTable[Total Units])

The problem here is that the occupancy % calculates correctly when I select one year and one month (e.g. September 2017); however, when I select "All" months and only one year (or when all years and all months are selected), the % calculation is wrong. 

Is there something I should be taking the average of? Or is there any other way to make the measure dynamic across all slicers selected?

I think it might be an easy answer, but something I just can't seem to figure out. Many thanks in advance for reading this!

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression in your card.  It makes a virtual table for each year/month combination in context and the occupancy for each, and then averages all those values.  Replace with your actual table/column names.

 

NewMeasure = AVERAGEX(SUMMARIZE(Date, Date[Year], Date[Month]), [Occupancy %])

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

mahoneypat
Microsoft Employee
Microsoft Employee

That measure shouldn't include blanks as zeros, but since your occupancy measure is 1 - every row will have a value.  To fix it, I would modify that measure.

 

Occupancy % = IF(NOT(ISBLANK([Vacancies])), 1 - (DIVIDE([Vacancies],[Total Units])))

 

I assume you have a simple measure for Vacancies so not critical to break it out into a variable first for performance.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

That measure shouldn't include blanks as zeros, but since your occupancy measure is 1 - every row will have a value.  To fix it, I would modify that measure.

 

Occupancy % = IF(NOT(ISBLANK([Vacancies])), 1 - (DIVIDE([Vacancies],[Total Units])))

 

I assume you have a simple measure for Vacancies so not critical to break it out into a variable first for performance.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat You are the best!! Thank you so much for that fix - the card is perfect now! 🙂 

mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression in your card.  It makes a virtual table for each year/month combination in context and the occupancy for each, and then averages all those values.  Replace with your actual table/column names.

 

NewMeasure = AVERAGEX(SUMMARIZE(Date, Date[Year], Date[Month]), [Occupancy %])

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat ! Thank you for your quick response!

That new measure you suggested works really well. I have one follow up question - the AVEREAGEX measure you suggested gives me the correct results for years in which I have data for all 12 months. However, for 2020, I only have data for months 1 to 9. In this case, when I select the year slicer to be 2020 and month as "All," the card visual returns 92.67% as my occupancy %, whereas the answer should be 90.23%. 

Any idea how I could deal with those blank months?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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