Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sks2701
Helper III
Helper III

how to format a number column

Hi- I have a revenue column in my data set - I would like to format this in the short format in the table view so for example if the cokumn contains 2140100000 as value in the table i want to format it like $2.1B and if the value is 698000000 i want it to format like $698M and so on - please can someone help the steps- thanks!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @sks2701 ,

 

If "[Total Funding Amount Currency (in USD)]" is a measure, it is unnecessary to use MIN() function. Just try this:

Measure =
VAR thisnumber = [Total Funding Amount Currency (in USD)]
RETURN
    IF (
        thisnumber < 1000000000,
        FORMAT ( thisnumber, "###,,.0M" ),
        FORMAT ( thisnumber, "###,,,.0B" )
    )

 

Or this:

Measure =
VAR SafeLog =
    IFERROR (
        ABS ( INT ( LOG ( ABS ( [Total Funding Amount Currency (in USD)] ), 1000 ) ) ),
        0
    )
VAR dp = 1
RETURN
    ROUND (
        DIVIDE ( [Total Funding Amount Currency (in USD)], 1000 ^ SafeLog ),
        dp
    )
        & SWITCH ( Safelog, 1, "K", 2, "M", 3, "bn", 4, "tn" )

 

If "[Total Funding Amount Currency (in USD)]" is a column, it is necessary to use function like SUM(), MIN(), etc.. Try this:

Measure =
VAR thisnumber =
    SUM ( [Total Funding Amount Currency (in USD)] )
RETURN
    IF (
        thisnumber < 1000000000,
        FORMAT ( thisnumber, "###,,.0M" ),
        FORMAT ( thisnumber, "###,,,.0B" )
    )

 

Or this:

Measure =
VAR SafeLog =
    IFERROR (
        ABS (
            INT ( LOG ( ABS ( SUM ( [Total Funding Amount Currency (in USD)] ) ), 1000 ) )
        ),
        0
    )
VAR dp = 1
RETURN
    ROUND (
        DIVIDE ( SUM ( [Total Funding Amount Currency (in USD)] ), 1000 ^ SafeLog ),
        dp
    )
        & SWITCH ( Safelog, 1, "K", 2, "M", 3, "bn", 4, "tn" )

 

 

Reference: Auto-Format Numbers in Billions, Millions, Thousan... - Microsoft Power BI Community

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
mahoneypat
Employee
Employee

Ideally, you would use Custom Format Strings to do this, but it does not appear to work the same as Excel when adding a condition.  For example, this custom format string works in Excel but not in Power BI Desktop.

 

[<100000000]#,,.0"M";#,,,.0"B"

 

However, you can write a DAX expression with an IF and the FORMAT function to get the same result.  Don't add this as a column to your table (since it returns text), but use it in a Measure once all your calculation is done to return the result in the desired format.

 

mahoneypat_0-1619357684663.png

 

NumberFormat =
VAR thisnumber =
    MIN ( CustomNumber[Formatted] )
RETURN
    IF (
        thisnumber < 1000000000,
        FORMAT ( thisnumber"###,,.0M" ),
        FORMAT ( thisnumber"###,,,.0B" )
    )

 

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hello @mahoneypat - thank you so much for your time, however this is still not working for me . attaching a screen shot for your reference. please can you look into it.

 

sks2701_0-1619422524172.png

 

Remove "NumberFormat =" (that is what I called the measure but you already have a name for it.  Also replace what is in the MIN(  ) with your actual TableName[ColumnName].

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


no luck 

sks2701_1-1619441311684.png

 

Icey
Community Support
Community Support

Hi @sks2701 ,

 

If "[Total Funding Amount Currency (in USD)]" is a measure, it is unnecessary to use MIN() function. Just try this:

Measure =
VAR thisnumber = [Total Funding Amount Currency (in USD)]
RETURN
    IF (
        thisnumber < 1000000000,
        FORMAT ( thisnumber, "###,,.0M" ),
        FORMAT ( thisnumber, "###,,,.0B" )
    )

 

Or this:

Measure =
VAR SafeLog =
    IFERROR (
        ABS ( INT ( LOG ( ABS ( [Total Funding Amount Currency (in USD)] ), 1000 ) ) ),
        0
    )
VAR dp = 1
RETURN
    ROUND (
        DIVIDE ( [Total Funding Amount Currency (in USD)], 1000 ^ SafeLog ),
        dp
    )
        & SWITCH ( Safelog, 1, "K", 2, "M", 3, "bn", 4, "tn" )

 

If "[Total Funding Amount Currency (in USD)]" is a column, it is necessary to use function like SUM(), MIN(), etc.. Try this:

Measure =
VAR thisnumber =
    SUM ( [Total Funding Amount Currency (in USD)] )
RETURN
    IF (
        thisnumber < 1000000000,
        FORMAT ( thisnumber, "###,,.0M" ),
        FORMAT ( thisnumber, "###,,,.0B" )
    )

 

Or this:

Measure =
VAR SafeLog =
    IFERROR (
        ABS (
            INT ( LOG ( ABS ( SUM ( [Total Funding Amount Currency (in USD)] ) ), 1000 ) )
        ),
        0
    )
VAR dp = 1
RETURN
    ROUND (
        DIVIDE ( SUM ( [Total Funding Amount Currency (in USD)] ), 1000 ^ SafeLog ),
        dp
    )
        & SWITCH ( Safelog, 1, "K", 2, "M", 3, "bn", 4, "tn" )

 

 

Reference: Auto-Format Numbers in Billions, Millions, Thousan... - Microsoft Power BI Community

 

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Icey thanks a ton - the below formula  worked as Total Funding Amount Currency (in USD) is a column

 

Measure = VAR thisnumber = SUM ( [Total Funding Amount Currency (in USD)] ) RETURN IF ( thisnumber < 1000000000, FORMAT ( thisnumber, "###,,.0M" ), FORMAT ( thisnumber, "###,,,.0B" ) )

 

However in the table visual , how can i arrange this measure column from highest to lowest value so currently with the present view the B is not appearing in the top row- please check the below screen shot.

 

sks2701_0-1619676586476.png

 

Icey
Community Support
Community Support

Hi @sks2701 ,

 

You can put the "[Total Funding Amount Currency (in USD)]" column into your Table visual and then close the option of "Word Wrap" of "Column header" and "Value" in the visual formatting field. Then, you can hide the column.

sort measure.gif

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You are missing the  ( ) in your MIN function.  MIN(Table[Total ...])

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


watkinnc
Super User
Super User

I bet Column From Examples would tackle that with ease...


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors