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
michellepace
Resolver III
Resolver III

How to format result in switch statement?

Hello,

In the screenshot below I give my user the abolity to compare months either as an actual value or as a %. The problem is that I do not know how to force a percent format should my user select "As Percentage". In the (commented out) dax code below, I have tried to use the format() function but this breaks my entire visualisation. 

Could anyone help me please?

 

Diff LM = 
SWITCH( TRUE(),
    [Selected Metric] = "By Amount", [Diff. to LM],
    [Selected Metric] = "By Percent", [% Diff to LM],
    // [Selected Metric] = "By Percent", format([% Diff to LM], "Percent"),
[Diff. to LM] )

 

screenshot.png

 

When I try to format my percentage case, I loose all my values like so:

 

screenshot2.png

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @michellepace ,

 

You can have a look at this video.

 

https://www.youtube.com/watch?v=xV8x7OTXIkE

 

Regards,


Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Anonymous
Not applicable

Well, the short answer is: You can't do this unless you use the very newest feature that's only available through Tabular Editor called "calculation groups." Your only option right now is to create a new measure, only for display purposes, that will output correctly formatted values. However, the values will be TEXT, not real numbers. Such a measure should only be used in visualizations, not in calculations. For calculations you should use a measure that returns raw numbers.
Fowmy
Super User
Super User

@michellepace 

Your measure seems fine, can you try it on new table visual. Check your Slicer it it returns a single value as expected. 

 

Diff LM = 
SWITCH( TRUE(),
    [Selected Metric] = "By Amount", [Diff. to LM],
    [Selected Metric] = "By Percent", FORMAT([% Diff to LM], "Percent"),
    [Diff. to LM] 
)

 

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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