Saturday, May 25, 2024

How to format values using FORMAT function in Power BI DAX

How to format numbers using FORMAT function in Power BI DAX
The FORMAT is a formatting function in DAX that formats a value based on a format string.
Formatting Numbers:
FormatValues=

VAR _General1 = ROW ( "Value_to_Format", "abc.1234" ,"Format_String","General",
                "Formatted_Value",FORMAT ("abc.1234", "General" ) )
VAR _General2 = ROW ( "Value_to_Format", 1234,"Format_String","General",
                "Formatted_Value",FORMAT ("1234", "General" ) )
VAR _Standard = ROW ( "Value_to_Format", 1234.5678 ,"Format_String","Standard",
                "Formatted_Value",FORMAT (1234.5678, "Standard" ) )
VAR _Fixed = ROW ( "Value_to_Format", 1234.5678 ,"Format_String","Fixed",
                "Formatted_Value",FORMAT (1234.5678, "Fixed" ) )
VAR _Number1 = ROW ( "Value_to_Format", 1234.5678 ,"Format_String","#,0.00",
                "Formatted_Value",FORMAT (1234.5678, "#,0.00" ) )
VAR _Thousand = ROW ( "Value_to_Format", 1234567890 ,"Format_String","$#,0,.0#K",
                "Formatted_Value",FORMAT (1234567890, "$#,0,.0#K" ) )
VAR _Million = ROW ( "Value_to_Format", 1234567890 ,"Format_String","$#,0,,.0#M",
                "Formatted_Value",FORMAT (1234567890, "$#,0,,.0#M" ) )
VAR _Billion = ROW ( "Value_to_Format", 1234567890 ,"Format_String","$#,0,,,.0#B",
                "Formatted_Value",FORMAT (1234567890, "$#,0,,,.0#B" ) )
VAR _Trillion = ROW ( "Value_to_Format", 1234567890 ,"Format_String","$#,0,,,,.0#T",
                "Formatted_Value",FORMAT (1234567890, "$#,0,,,,.0#T" ) )  
VAR _Positive1 = ROW ( "Value_to_Format", 1234.12 ,"Format_String","#,0.00",
                "Formatted_Value",FORMAT (1234.12, "#,0.00" ) )
VAR _Positive2 = ROW ( "Value_to_Format", 1234.12 ,"Format_String","#,0.00;(#,0.00)",
                "Formatted_Value",FORMAT (1234.12, "#,0.00;(#,0.00)" ) )
VAR _Positive3 = ROW ( "Value_to_Format", 1234.12 ,"Format_String","#,#.##;(#,#.##);-",
                "Formatted_Value",FORMAT (1234.12, "#,#.##;(#,#.##);-" ) )
VAR _Negative1 = ROW ( "Value_to_Format", -1234.12 ,"Format_String","#,0.00",
                "Formatted_Value",FORMAT (-1234.12, "#,0.00" ) )
VAR _Negative2 = ROW ( "Value_to_Format", -1234.12 ,"Format_String","#,0.00;(#,0.00)",
                "Formatted_Value",FORMAT (-1234.12, "#,0.00;(#,0.00)" ) )
VAR _Negative3 = ROW ( "Value_to_Format", -1234.12 ,"Format_String","#,#.##;(#,#.##);-",
                "Formatted_Value",FORMAT (-1234.12, "#,#.##;(#,#.##);-" ) )
VAR _Percent1 = ROW ( "Value_to_Format", 0.2345,"Format_String","Percent",
                "Formatted_Value",FORMAT (0.2345, "Percent" ) )
VAR _Percent2 = ROW ( "Value_to_Format", 0.2345,"Format_String","#.00%",
                "Formatted_Value",FORMAT (0.2345, "#.00%" ) )
VAR _Percent3 = ROW ( "Value_to_Format", 0.2345,"Format_String","00.00%",
                "Formatted_Value",FORMAT (0.2345, "00.00%" ) )
VAR _Currency1 = ROW ( "Value_to_Format", 1234.5678,"Format_String","$#,0",
                "Formatted_Value",FORMAT (1234.5678, "$#,0" ) )
VAR _Currency2 = ROW ( "Value_to_Format", 1234.5678,"Format_String","$#.00",
                "Formatted_Value",FORMAT (1234.5678, "$#.00" ) )
VAR _Currency3 = ROW ( "Value_to_Format", 1234.5678,"Format_String","$#,0.00",
                "Formatted_Value",FORMAT (1234.5678, "$#,0.00" ) )
VAR _Currency4 = ROW ( "Value_to_Format", 1234.5678,"Format_String","""US$"" #,0.00",
                "Formatted_Value",FORMAT (1234.5678, """US$"" #,0.00" ) )
VAR _Currency5= ROW ( "Value_to_Format", 1234.5678,"Format_String","""€"" #,0.00",
                "Formatted_Value",FORMAT (1234.5678, """€"" #,0.00" ) )
VAR _Scientific = ROW ( "Value_to_Format", 1234.5678,"Format_String","Scientific",
                "Formatted_Value",FORMAT (1234.5678, "Scientific" ) )
VAR _Boolean1 = ROW ( "Value_to_Format", "True/False","Format_String","True/False",
                "Formatted_Value",FORMAT (TRUE(), "True/False" ) )
VAR _Boolean2 = ROW ( "Value_to_Format", "On/Off","Format_String","On/Off",
                "Formatted_Value",FORMAT (FALSE(), "On/Off" ) )
VAR _Boolean3 = ROW ( "Value_to_Format", "Yes/No","Format_String","Yes/No",
                "Formatted_Value",FORMAT (TRUE(), "Yes/No" ) )
/*
VAR _Zero1 = ROW ( "Value_to_Format", 0 ,"Format_String","#,0.00",
                "Formatted_Value",FORMAT (0, "#,0.00" ) )
VAR _Zero2 = ROW ( "Value_to_Format", 0 ,"Format_String","#,0.00;(#,0.00)",
                "Formatted_Value",FORMAT (0, "#,0.00;(#,0.00)" ) )
VAR _Zero3 = ROW ( "Value_to_Format", 0 ,"Format_String","#,#.##;(#,#.##);-",
                "Formatted_Value",FORMAT (0, "#,#.##;(#,#.##);-" ) )
VAR _Blank1 = ROW ( "Value_to_Format", BLANK() ,"Format_String","#,0.00",
                "Formatted_Value",FORMAT (BLANK(), "#,0.00" ) )
VAR _Blank2 = ROW ( "Value_to_Format", BLANK() ,"Format_String","#,0.00;(#,0.00)",
                "Formatted_Value",FORMAT (BLANK(), "#,0.00;(#,0.00)" ) )
VAR _Blank3 = ROW ( "Value_to_Format", BLANK() ,"Format_String","#,#.##;(#,#.##);-",
                "Formatted_Value",FORMAT (BLANK(), "#,#.##;(#,#.##);-" ) )
*/

RETURN
UNION (
    _General1,_General2, _Standard,_Fixed,_Number1,
    _Thousand, _Million,_Billion,_Trillion,
    _Positive1,_Positive2,_Positive3, _Negative1,_Negative2,_Negative3,
    _Percent1,_Percent2,_Percent3,
    _Currency1,_Currency2,_Currency3,_Currency4,_Currency5,
    _Scientific, _Boolean1,_Boolean2,_Boolean3
    /* _Zero1,Zero2,Zero3, _Blank1,Blank2,Blank3 */
    )

Result:
--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog