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
738o51
Helper II
Helper II

Conditional formatting for number format of measure

Hi everyone,

 

I am working on a report to show census and occupancy of our hospital where census is the count of patients, and occupancy is census/hospital beds. Therefore, census should be formatted as a number (with no decimal places) and occupancy should be a percentage.

 

There are several visuals where I want to switch between these metrics. For example, to show trends in census and occupancy over the past year, I built a line graph that allows me to switch the value of the graph by clicking a button. I used these instructions: https://powerbi.tips/2019/08/dynamic-visuals-using-buttons/

and the meausre is: 

Metric =
SWITCH(
SELECTEDVALUE(Metric[Metric Number]),
1,[Occupancy],
2,[Census],
[Occupancy]
)

 

My problem is now that as I switch between occupancy and census, I cannot get the number formatting of that measure to change as well. Is there a way for me to format my metric to show % when I click the "Occupancy" button and a number when I click the "Census" button?

 

Any help would be appreciated! I cannot attach a real pbix file because of confidential patient information, unfortunately.

1 ACCEPTED SOLUTION
rajulshah
Super User
Super User

Hello @738o51,

Please try the following DAX:

Metric =
SWITCH(
SELECTEDVALUE(Metric[Metric Number]),
1,FORMAT([Occupancy],"Percent"),
2,[Census],
FORMAT([Occupancy],"Percent")
)

Let me know if this doesn't help.

View solution in original post

2 REPLIES 2
rajulshah
Super User
Super User

Hello @738o51,

Please try the following DAX:

Metric =
SWITCH(
SELECTEDVALUE(Metric[Metric Number]),
1,FORMAT([Occupancy],"Percent"),
2,[Census],
FORMAT([Occupancy],"Percent")
)

Let me know if this doesn't help.

Thanks! 

 

I used your Dax but made used "#%" rather than "Percent" to get rid of the decimal places.

 

I appreciate your help!

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.