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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
dokat
Post Prodigy
Post Prodigy

Dynamically change data format based on slicer selection

Hi,

 

I have a stacked column report where i would like to chamge data format based on slicer selection. I put the below code under data labels-values, custom labels- field. Code works for the most part except for when trade rate is selected in the slicer. Below you will find the screen shot of results when trade rate is selected. How can i show actual percentage rather than 0.0%. Thanks

 

Output Sales Format = 
VAR Sales = CALCULATE(Output[Output Selected Calculation])
VAR SlicerSelection = SELECTEDVALUE('Output Slicer Table'[P&L])
VAR FormatString = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", "0.00", IF(SlicerSelection = "Trade Rate", "0.0%", IF(Sales > 1000000, "0.0M", "0.0K")))
VAR RoundedSales = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", ROUND(Sales, 2), IF(Sales > 1000000, ROUND(Sales/1000000, 1), ROUND(Sales/1000, 1)))
RETURN
FORMAT(RoundedSales, FormatString)

 Screenshot 2023-08-13 213240.png

1 ACCEPTED SOLUTION

i figured out. i modified the code little bit.

Output Sales Format = 
VAR Sales = CALCULATE(Output[Output Selected Calculation])
VAR SlicerSelection = SELECTEDVALUE('Output Slicer Table'[P&L])
VAR FormatString = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", "0.000", IF(SlicerSelection = "Trade Rate",format(CALCULATE(Output[Output Selected Calculation]),"0.0%"), IF(Sales > 1000000, "0.0M", "0.0K")))
VAR RoundedSales = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", ROUND(Sales, 3), IF(Sales > 1000000, ROUND(Sales/1000000, 1), ROUND(Sales/1000, 1)))
RETURN
FORMAT(RoundedSales, FormatString)

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@dokat you can take advantage of the new dynamic format option available in Power BI, check out the video here:  From Thousands to Billions: The Power of Dynamic Formatting in Power BI - April 2023 Power BI Update...

 

👉 Learn Power BI and Fabric - subscribe to our YT channel - @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤️



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

i figured out. i modified the code little bit.

Output Sales Format = 
VAR Sales = CALCULATE(Output[Output Selected Calculation])
VAR SlicerSelection = SELECTEDVALUE('Output Slicer Table'[P&L])
VAR FormatString = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", "0.000", IF(SlicerSelection = "Trade Rate",format(CALCULATE(Output[Output Selected Calculation]),"0.0%"), IF(Sales > 1000000, "0.0M", "0.0K")))
VAR RoundedSales = IF(SlicerSelection = "ASP" || SlicerSelection = "ansp" || SlicerSelection = "cogs", ROUND(Sales, 3), IF(Sales > 1000000, ROUND(Sales/1000000, 1), ROUND(Sales/1000, 1)))
RETURN
FORMAT(RoundedSales, FormatString)

@parry2k Thanks. In theory the code i have works in similar way in the vide you shared, The issue i am coming accross is when trade rate slicer is selected it returns "0.0%" as text rather than 20.5% or 38.2%. It iis not returning number.  Strangely all others formula works fine.

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.