Just a quick blog post today. Someone had a scenario where they wanted to have a different number of decimal points based on the items on the rows. Initially they wanted to go with a calculated column but it is much easier to do this using the FORMAT function in DAX. Using the FORMAT function you can return the numerical value any way you want it.
Let’s take the following example. I have the several different devices and I want to format them all differently. I can write a single measure that return different formatting for each device.
This would be the measure I would write:
Measure = if(HASONEVALUE(Device[DeviceName]),
,”Aircard 1″, FORMAT([Sum of Revenue], “0.0”)
,”Aircard 2″, FORMAT([Sum of Revenue], “0.00”)
,”Aircard 3″, FORMAT([Sum of Revenue], “$0.000″)
,”Aircard 4”, FORMAT([Sum of Revenue], “0.0000”)
,FORMAT([Sum of Revenue], “0”)
As you can see the results are what we expect:
You can also use this to show different symbols as you would use this when doing currency conversion.
One thing to observe here is that thanks to several performance optimizations the use of IF and SWITCH in Power BI desktop is significantly improved as compared to Power Pivot for Excel 2013 and SQL 2014.