For this workout, you are asked to create a DAX Measure that formats the dollar amounts in the left column to look like the right colum. Overall, when the amount is in the thousands or greater, display the number with 1 decimal place and show the corresponding letter.
(Note - the USD $ sign is provided, but feel free to update this to either leave off or include a difference currency symbol).
A PBI file is provided with a sample dataset or you may simply create your own.
I hate if/switch conditions. I prefer math approach - if it exists. Here is a math based approach, extended also to “T” suffix (trillions). No safeguarding if number is bigger than Trillion. Enjoy.
Amount Text =
VAR suffixVec = " kMBT"
VAR actAmount =
SUM ( input[Dollar Amount] )
VAR actThousandToThePowerOf =
QUOTIENT ( ROUNDDOWN ( LOG ( actAmount, 10 ), 0 ), 3 )
VAR outNumber =
DIVIDE ( actAmount, POWER ( 1000, actThousandToThePowerOf ) )
VAR outFormat =
“$”
& IF (
actThousandToThePowerOf = 0,
“#”,
“#.0”
& MID ( suffixVec, actThousandToThePowerOf + 1, 1 )
)
RETURN
FORMAT ( outNumber, outFormat )
These are great variations. One approach that I didn’t think of which I find very unique is @Pavel.Adam use of having the letters stored in a variable and then using the MID() text function to use the log value from a positioning standpoint.
Well, I use a data catalog based table that (with other attributes) specifies what measure should be formatted how: rounding, decimals, units. Doing so, customer is able to define its own requirements to each KPI - without me or any other DAX developer to deal with DAX formatting.
Using such a table, I define formatting option in Power Query - it is much faster to retrieve short string than to create such a string in DAX measure again and again.