Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DAX number format with a plus or minus sign

Tags:

powerbi

dax

I want to format DAX measure so that value 0.105 is displayed as +10.5%, and value -0.105 is displayed as -10.5%. Important for me is the plus sign. I failed using FORMAT(measure, "+0.0%").

I cannot find anything helpful in FORMAT function doc: https://msdn.microsoft.com/query-bi/dax/custom-numeric-formats-for-the-format-function

The only solution I can think of is handling it with IF or SWITCH function. Is there a way to avoid it?

IF(variable>0, "+"&variable, variable)
like image 963
Przemyslaw Remin Avatar asked Aug 20 '18 13:08

Przemyslaw Remin


2 Answers

You need to create custom format for both positive and negative numbers:

Formatted Value = FORMAT( [Measure], "+0.0%;-0.0%")

Result: enter image description here

In general, custom format string consists of 4 parts, separated by ;

Positive values; Negative values; Zero values; Text values

One section is required, others are optional. So, to avoid + in front of zero, a full code might be:

Formatted Value = FORMAT( [Measure], "+0.0%;-0.0%;"0")
like image 159
RADO Avatar answered Oct 16 '22 23:10

RADO


I'm a bit late to the game perhaps. And yes, formatting negative numbers in parentheses was a bit difficult in Power BI before. As other answers suggest, it would involve the FORMAT function. But today you can use custom formatting for a measure. For example "#,##0.0, (#.##0.0)". Hope that helps. You can find a more elaborate explanation here: 

Format Negative values between Parentheses

Keep crushing it!

Rick

like image 44
Rick de Groot - gorilla.bi Avatar answered Oct 16 '22 22:10

Rick de Groot - gorilla.bi