Error in dax for the day workout 1

hello,
i am studying the solution to workout 1 for DAX…
I can not see why I am seeing an error

The DAX code is:

Formatted Result =

// Uses alternate parameter to prevent card from showing blank
// if no selection is made in table
VAR _SelVal = SELECTEDVALUE( Data[Dollar Amount], -9999)

VAR _Number =
SWITCH( TRUE(),
_SelVal < 1000, _SelVal,
_SelVal < 1000000, DIVIDE( _SelVal, 1000),
_SelVal < 1000000000, DIVIDE( _SelVal, 1000000),
DIVIDE( _SelVal, 1000000000)
)

VAR _NumFormat =
SWITCH( TRUE(),
_SelVal < 1000, “$##0”,
_SelVal < 1000000, “$##0.0,” & “k”,
_SelVal < 1000000000, “$##0.00,” & “M”,
“$##0.0,” & “B”
)

VAR Result =
IF( _SelVal = -9999,
“Value not selected”,
FORMAT( _Number, _NumFormat )
)

RETURN Result

If you get rid of the default value of -9999 from _SelVal, and instead just test for NOT ISBLANK(_SelVal) does that resolve the issue, it may be that the default result expects a text string

no, the error remains

Just re read through the measure, is this a measure to apply dynamic number formatting, where you select dynamic from the format options, and then measure in the options to apply it, if that is the case you can leave the selected value part as it was, and get rid of _Number, as the number wont change only the formatting applied to it, the _NumFormat will remain and the _Result would not be needed, you would just output the _NumFormat to apply to the underlying number, if I understand it correctly.

FYI Dynamic number formattting is in preview mode only. so becareful when you are doing this in live production.

make sure you go into options setting to get this option and setting

make sure that Dynamice format string for measures is checked.

thanks
Keith

1 Like