Character.FromNumber returns the character whose Unicode code point matches a given number. Available in Excel (Power Query), Power BI Desktop, and Power BI Service.
If you have a number like 65 and you want the character it stands for, which is A, this is the function you reach for.
Syntax of Character.FromNumber Function
Character.FromNumber(number as nullable number) as nullable text
where
number(required, nullable number). The Unicode code point to convert into a character. Passnulland you getnullback.
Returns: a one-character text value for the supplied code point. If number is null, it returns null.
In plain terms, you give it a number and it hands back the single character that number represents.
Example 1: Convert a code point to a character
Convert the code point 65 into its character.
Character.FromNumber(65)
Result: A
The code point 65 is the letter A, so that is what comes back.
Example 2: Label table rows with letters A, B, C, D
A common use is turning a row position into a letter label.
Say you have a SurveyOptions table with the choices people can pick.
Here is the starting data:
| Choice |
|---|
| Coffee |
| Tea |
| Juice |
| Water |
Add a zero-based index, then build the label inside Table.AddColumn with Character.FromNumber(65+[Position]):
let
Source = Excel.CurrentWorkbook(){[Name="SurveyOptions"]}[Content],
Indexed = Table.AddIndexColumn(Source,"Position",0,1,Int64.Type),
AddLabel = Table.AddColumn(Indexed,"OptionLabel",each Character.FromNumber(65+[Position]),type text),
Removed = Table.RemoveColumns(AddLabel,{"Position"})
in
Removed
The result pairs each choice with a letter:
| Choice | OptionLabel |
|---|---|
| Coffee | A |
| Tea | B |
| Juice | C |
| Water | D |
Since 65 is the code point of A, 65+0 gives A, 65+1 gives B, and so on down the rows. If your positions live in a list rather than a table, you can do the same thing with List.Transform.
Example 3: Round-trip a character through its code point
Character.FromNumber is the inverse of Character.ToNumber, so the two can be chained to recover the original character.
Say you have a GradeBands table with single-letter grades.
Here is the starting data:
| Grade |
|---|
| B |
| D |
| F |
Use Character.ToNumber to get each code point, then Character.FromNumber to rebuild the letter:
let
Source = Excel.CurrentWorkbook(){[Name="GradeBands"]}[Content],
AddCode = Table.AddColumn(Source,"CodePoint",each Character.ToNumber([Grade]),Int64.Type),
AddBack = Table.AddColumn(AddCode,"Recovered",each Character.FromNumber([CodePoint]),type text)
in
AddBack
The Recovered column matches the original Grade column:
| Grade | CodePoint | Recovered |
|---|---|---|
| B | 66 | B |
| D | 68 | D |
| F | 70 | F |
Character.ToNumber("B") gives 66, and Character.FromNumber(66) gives B back, so the round trip lands where it started.
Example 4: Convert a low code point to a control character
Low code points map to invisible control characters rather than printable text.
Character.FromNumber(9)
Result: "#(tab)"
The code point 9 is the tab character. It produces a real character, but nothing visible in a cell, so the M engine shows it as the escape sequence "#(tab)".
Things to keep in mind with Character.FromNumber
- The input is a Unicode code point, not just ASCII.
65givesA, but you can also pass8226for a bullet or169for the copyright symbol. Hex literals work too, like0x1F600. - Control characters are invisible. Code points
0to31are control characters such as tab (9), line feed (10), and carriage return (13). They come back as a real character but show up as escapes like"#(tab)","#(lf)", or"#(cr)"instead of rendering. - The inverse is
Character.ToNumber. UseCharacter.ToNumberto find a code point andCharacter.FromNumberto rebuild the character. The two round-trip, as shown in Example 3. - Code points above U+FFFF return a surrogate pair. Astral-plane values like the emoji
0x1F600come back as a two-unit UTF-16 surrogate pair, which M displays as"#(0001F600)". nullpasses through. Because the parameter isnullable,Character.FromNumber(null)returnsnullinstead of throwing, which is handy when a column has blanks.- Out-of-range code points throw. A number outside the valid Unicode range (negative, or above
1114111) raises anExpression.Error.
Common questions about Character.FromNumber
What is the difference between Character.FromNumber and Text.From?
Text.From(65) turns the number 65 into the text "65", the digits themselves, much like Number.ToText does. Character.FromNumber(65) turns the code point 65 into the character A. One gives you the number as a string, the other gives you the character that number represents.
How do I insert a line break into a Power Query value?
Use Character.FromNumber(10) for a line feed, or Character.FromNumber(13)&Character.FromNumber(10) for a Windows CRLF. Concatenate it between text pieces, for example [Line1]&Character.FromNumber(10)&[Line2].
List of All Power Query Functions
Related Power Query Functions / Articles: