TEXT in DAX: month name, number as text
In Excel, the TEXT function writes a date or a number following a pattern. In DAX, FORMAT does the same job, with the same pattern letters. The difference to remember is elsewhere, in what you can still do with the result.
In Excel
For the month name of a date in column B:
It returns “January 2024.” For an amount written with a comma between the thousands:
It returns “250,000.”
In DAX, with FORMAT
FORMAT turns a date or a number into text, following a pattern you give it. It receives the value and the pattern, and returns the text written the way the pattern asks.
In our data, in a calculated column of Sales, the month name is written like this:
On row V001, it returns “January 2024.” The pattern takes “yyyy” for the year, just like Excel.
For a number, the pattern uses the comma for the thousands and the period for the decimals:
In a card with no filter, it shows “1,700,000.” With other regional settings, Power BI writes the result with the separators of that region, a space for French, for example.
What really changes
Like TEXT, FORMAT returns a text. A month written in letters sorts in alphabetical order, April before January, and SUM rejects a text.
For a number on its own in a visual, set the format of the measure in the Measure tools ribbon instead. Keep FORMAT for a number that goes into a sentence, like a title.
The full lesson shows all the signs of date and number patterns. Writing text
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
A card shows the “Revenue” measure, and you want to read 1,700,000 in it, with a comma between the thousands. The figure must remain usable in other calculations. What do you do?
Question 2
The calculated column Month = FORMAT( Sales[Date], "mmmm" ) is placed in a table sorted on this column, in ascending order. Which month shows first?
Question 3
You add the calculated column Amount Text = FORMAT( Sales[Amount], "#,0" ) to Sales, then you write the measure SUM( Sales[Amount Text] ). What happens?
- TEXT translates to FORMAT, with the same pattern letters, “yyyy” for the year.
- FORMAT returns a text. Keep the original date or number to sort and to calculate.