Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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.
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!
Solved! Go to Solution.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
@mahoneypat You are the best!! Thank you so much for that fix - the card is perfect now! 🙂
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
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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?
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
76 | |
61 | |
37 | |
33 |
User | Count |
---|---|
99 | |
56 | |
50 | |
42 | |
40 |