FORMAT DAX Function (Text)
Converts a value to text in the specified number format.
Syntax
Parameter | Attributes | Description |
---|---|---|
Value |
A number, or a formula that evaluates to a numeric value. |
|
Format |
A number format that you specify. |
Return values
A string containing Value formatted as defined by Format string.
The result is always a string, even when the value is blank.
Remarks
For information on how to use the Format string parameter:
- Numbers: Use predefined numeric formats or create custom numeric formats.
- Dates and times: Use predefined date/time formats or create user-defined date/time formats.
The format strings supported as an argument to the DAX FORMAT function are based on the format strings used by Visual Basic (OLE Automation), not on the format strings used by the .NET Framework. Therefore, you might get unexpected results or an error if the argument does not match any defined format strings. For example, “p” as an abbreviation for “Percent” is not supported. Strings that you provide as an argument to the FORMAT function that are not included in the list of predefined format strings are handled as part of a custom format string, or as a string literal.
In order to make sure a literal is not interpreted as a format string, embed the literal between double quotes as in the examples.
The name of weekdays and months depends on the international settings of the database (or Power BI Desktop file).
Examples
-- FORMAT is a formatting function that formats a value based -- on a format string. EVALUATE { ( "Percent", FORMAT ( 0.742, "Percent" ) ), ( "Currency (1)", FORMAT ( 1234.567, "$#,0.00" ) ), ( "Currency (2)", FORMAT ( 1234.567, """US$"" #,0.00" ) ), ( "Date (1)", FORMAT ( DATE ( 2019, 3, 28 ), "yyyy-mm-dd" ) ), ( "Date (2)", FORMAT ( DATE ( 2019, 3, 28 ), "m/d/yy" ) ) }
Value1 | Value2 |
---|---|
Percent | 74.20% |
Currency (1) | $1,234.57 |
Currency (2) | US$ 1,234.57 |
Date (1) | 2019-03-28 |
Date (2) | 3/28/19 |
-- FORMAT accepts a set of predefined format strings to format numbers EVALUATE { ( "General Number", FORMAT( 12345.67, "General Number" ) ), ( "Currency" , FORMAT( 12345.67, "Currency" ) ), ( "Fixed" , FORMAT( 12345.67, "Fixed" ) ), ( "Standard" , FORMAT( 12345.67, "Standard" ) ), ( "Percent" , FORMAT( 12345.67, "Percent" ) ), ( "Scientific" , FORMAT( 12345.67, "Scientific" ) ), ( "True/False" , FORMAT( TRUE, "True/False" ) ), ( "On/Off" , FORMAT( FALSE, "On/Off" ) ), ( "Yes/No" , FORMAT( TRUE, "Yes/No" ) ) }
Value1 | Value2 |
---|---|
General Number | 12345.67 |
Currency | $12,345.67 |
Fixed | 12345.67 |
Standard | 12,345.67 |
Percent | 1234567.00% |
Scientific | 1.23E+04 |
True/False | True |
On/Off | Off |
Yes/No | Yes |
-- Regardless of the format string, if the value argument is -- BLANK, FORMAT returns an empty string EVALUATE { ( "General Number", FORMAT ( BLANK (), "General Number" ) ), ( "Currency" , FORMAT ( BLANK (), "Currency" ) ), ( "Fixed" , FORMAT ( BLANK (), "Fixed" ) ), ( "Standard" , FORMAT ( BLANK (), "Standard" ) ), ( "Percent" , FORMAT ( BLANK (), "Percent" ) ), ( "Scientific" , FORMAT ( BLANK (), "Scientific" ) ), ( "True/False" , FORMAT ( BLANK (), "True/False" ) ), ( "On/Off" , FORMAT ( BLANK (), "On/Off" ) ), ( "Yes/No" , FORMAT ( BLANK (), "Yes/No" ) ) }
Value1 | Value2 |
---|---|
General Number | |
Currency | |
Fixed | |
Standard | |
Percent | |
Scientific | |
True/False | |
On/Off | |
Yes/No |
-- Custom numeric format string can have up to 3 sections: -- One section : applied to all the values -- Two sections : first for positive and zero, second for negative -- Three sections: first for positive, second for negative, third for zero EVALUATE { ( "Positive", FORMAT ( 1980.126, "#,0.00" ) ), ( "Negative", FORMAT ( -1980.1 , "#,0.00" ) ), ( "Zero", FORMAT ( 0 , "#,0.00" ) ), ( "Blank", FORMAT ( BLANK () , "#,0.00" ) ) } EVALUATE { ( "Positive", FORMAT ( 1980.126, "#,0.00;(#,0.00)" ) ), ( "Negative", FORMAT ( -1980.1 , "#,0.00;(#,0.00)" ) ), ( "Zero", FORMAT ( 0 , "#,0.00;(#,0.00)" ) ), ( "Blank", FORMAT ( BLANK () , "#,0.00;(#,0.00)" ) ) } EVALUATE { ( "Positive", FORMAT ( 1980.12, "#,#.##;(#,#.##);-" ) ), ( "Negative", FORMAT ( -1980.12, "#,#.##;(#,#.##);-" ) ), ( "Zero", FORMAT ( 0 , "#,#.##;(#,#.##);-" ) ), ( "Blank", FORMAT ( BLANK (), "#,#.##;(#,#.##);-" ) ) }
Value1 | Value2 |
---|---|
Positive | 1,980.13 |
Negative | -1,980.10 |
Zero | 0.00 |
Blank |
Value1 | Value2 |
---|---|
Positive | 1,980.13 |
Negative | (1,980.10) |
Zero | 0.00 |
Blank |
Value1 | Value2 |
---|---|
Positive | 1,980.12 |
Negative | (1,980.12) |
Zero | – |
Blank |
-- FORMAT accepts a set of predefined format strings for Date/Time DEFINE VAR D = DATE ( 2021, 1, 2 ) VAR T = TIME ( 15, 30, 0 ) VAR DT = D + T EVALUATE { ( "General Date", FORMAT ( DT, "General Date" ) ), ( "Long Date" , FORMAT ( DT, "Long Date" ) ), ( "Medium Date" , FORMAT ( DT, "Medium Date" ) ), ( "Short Date" , FORMAT ( DT, "Short Date" ) ), ( "Long Time" , FORMAT ( DT, "Long Time" ) ), ( "Medium Time" , FORMAT ( DT, "Medium Time" ) ), ( "Short Time" , FORMAT ( DT, "Short Time" ) ) }
Value1 | Value2 |
---|---|
General Date | 1/2/2021 3:30:00 PM |
Long Date | Saturday, January 2, 2021 |
Medium Date | 02-Jan-21 |
Short Date | 1/2/2021 |
Long Time | 3:30:00 PM |
Medium Time | 03:30 PM |
Short Time | 15:30 |
-- You can use simple date formatting composing the format string -- with dd, mm, yyyy, hh, mm and ss. -- The "c" format string adapts to the value, showing what is relevant DEFINE VAR D = DATE ( 2020, 1, 2 ) VAR T = TIME ( 15, 30, 0 ) VAR DT = D + T EVALUATE { ( "dd/mm/yyyy" , FORMAT ( DT, "dd/mm/yyyy" ) ), ( "hh:nn:ss" , FORMAT ( DT, "hh:nn:ss" ) ), -- "nn" for minutes ( "hh:mm:ss" , FORMAT ( DT, "hh:mm:ss" ) ), -- "mm" works too, if hh before ( "c (full)" , FORMAT ( DT, "c" ) ), ( "c (Date only)", FORMAT ( D, "c" ) ), ( "c (Time only)", FORMAT ( T, "c" ) ) }
Value1 | Value2 |
---|---|
dd/mm/yyyy | 02/01/2020 |
hh:nn:ss | 15:30:00 |
hh:mm:ss | 15:30:00 |
c (full) | 1/2/2020 3:30:00 PM |
c (Date only) | 1/2/2020 |
c (Time only) | 3:30:00 PM |
-- The "m" format string offers many options, depending on the -- number of consecutive m DEFINE VAR D = DATE ( 2020, 1, 2 ) EVALUATE { ( "m" , FORMAT ( D, "m" ) ), -- 1 or 2 digits ( "mm" , FORMAT ( D, "mm" ) ), -- always 2 digits ( "mmm" , FORMAT ( D, "mmm" ) ), -- short day of month ( "mmmm" , FORMAT ( D, "mmmm" ) ) -- long day of month }
Value1 | Value2 |
---|---|
m | 1 |
mm | 01 |
mmm | Jan |
mmmm | January |
-- The "d" format string offers many options, depending on the -- number of consecutive d DEFINE VAR D = DATE ( 2020, 1, 9 ) EVALUATE { ( "d" , FORMAT ( D, "d" ) ), -- 1 or 2 digits ( "dd" , FORMAT ( D, "dd" ) ), -- always 2 digits ( "ddd" , FORMAT ( D, "ddd" ) ), -- short day of week ( "dddd" , FORMAT ( D, "dddd" ) ), -- long day of week ( "ddddd" , FORMAT ( D, "ddddd" ) ), -- short date ( "dddddd" , FORMAT ( D, "dddddd" ) ) -- long date }
Value1 | Value2 |
---|---|
d | 9 |
dd | 09 |
ddd | Thu |
dddd | Thursday |
ddddd | 1/9/2020 |
dddddd | Thursday, January 9, 2020 |
Related articles
Learn more about FORMAT in the following articles:
-
Creating a simple date table in DAX
This article shows how to build a basic date table using a calculated table and DAX. » Read more
Last update: Mar 1, 2021 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
MSDN documentation: https://docs.microsoft.com/en-us/dax/format-function-dax