Search code examples
powerbidaxpowerbi-desktopmeasure

How to format numbers in DAX, based on a condition


I have var _sales and I would like to format it based on its decimal numbers.

Expected Answer:

If the number is `15.506,514 Million` = `15 M` 
`15.606,514 Million` = `16 M`

How to get around the code below. many thanks in advance.

var _result =
SWITCH(
    TRUE(),
    ABS( _sales ) >= 1000000, FORMAT( _sales, "$#,##0,,M"),
    ABS( _sales ) >= 1000, FORMAT( _sales, "$#,##0,k"),
    FORMAT( _sales, "$#,##0" )
)
RETURN _result

Solution

  • Try the following. You may need to switch the , and . for your regional settings.

    Either

    FORMAT( _sales, "0,,.M" )

    or

    FORMAT( _sales, "0..,M" )