Text.From
Converts a number, date, time or logical value to text.
Text.From(value as any, optional culture as nullable text) as nullable textReturns: The value as text, or null when the input is null.
What it does
Text.From turns a value into text. Finance teams use it to join a number to a text column, to pad an account number with zeros, or to build a label. It follows the culture of the machine unless you say otherwise, and that is the trap. A value written with a decimal point on one computer can come out with a decimal comma on another.
Syntax and arguments
- value: the number, date, time or logical value to convert.
- culture (optional): a culture name such as "en-US" or "de-DE". Pass one whenever the text must be the same on every machine.
Example
A monthly close file builds a key from a period number and an account number. The period is a number, so Text.From makes it text before the key is joined.
let
Period = 9,
Account = 4010,
Key = Text.From(Period) & "-" & Text.From(Account),
Decimal = Text.From(1234.5, "en-US"),
German = Text.From(1234.5, "de-DE")
in
{Key, Decimal, German}
Key is "9-4010". With "en-US" the decimal is "1234.5", and with "de-DE" the same number is "1234,5". The two text values are not the same, which is why the culture should be stated.
Example: a second, different use
Convert a date to text with Date.ToText and an explicit format, instead of relying on Text.From, so the output looks the same every time.
Things to watch
- Without a culture, the result depends on the settings of the machine that refreshes the query.
- Text.From on a date gives the date in the culture's usual layout. Use Date.ToText with a format string when the layout matters.
- Converting a number such as 0420 loses its leading zeros. Use Text.PadStart after converting.
- Null in gives null out.
In business terms
Keys, labels and export files need text in a fixed form. Converting with a stated culture keeps a monthly key the same on the analyst's laptop and on the server that refreshes the report.