Search code examples
powerbidaxpowerbi-desktopmeasuredaxstudio

Round/format numbers in powerbi


I am trying to round numbers using the code below, which does round the number to 9M if the number has decimals 9,000,000.55, but if the number is 9,000,000 it does not round. How to get around this? many thanks in advance.

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

)


Solution

  • EDIT

    Here you go.

    Column = SWITCH(
    TRUE(),
    ABS([_sales]) >= 1000000, FORMAT( [_sales], "$#,##0,,M"),
    ABS([_sales]) >= 1000, FORMAT( [_sales], "$#,##0,k"),
    FORMAT( [_sales], "$#,##0" )
    
    )
    

    The code works fine as far as I can see.

    enter image description here