Text.ToBinary is a Power Query M function that encodes a text value into a binary value using a specified encoding. The function returns the binary value resulting from the encoding process.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Text.ToBinary(
text as nullable text,
optional encoding as nullable number,
optional includeByteOrderMark as nullable logical,
) as nullable binary
Argument | Attribute | Description |
---|---|---|
text | ||
encoding | optional | Uses the TextEncoding.Type to specify the text’s binary encoding format. By default, if not provided, the argument uses TextEncoding.Utf8 (UTF8 binary form). Other available options are: – TextEncoding.Unicode: use the UTF16 little-endian binary form. – TextEncoding.Utf16: use the UTF16 little-endian binary form. – TextEncoding.BigEndianUnicode: use the UTF16 big endian binary form. – TextEncoding.Windows: use the Windows binary form. – TextEncoding.Ascii: use the ASCII binary form. |
includeByteOrderMark | optional |
Description
The Text.ToBinary function encodes a text value using a specified encoding type.
Examples
The Text.ToBinary
function is not commonly used, but it can be helpful in certain scenarios, such as identifying diacritic characters. Let’s explore how it works with an example.
Suppose you have the text “Guillermo Stábile” and want to convert it to binary using Text.ToBinary
. Then, you convert it back to text using Text.FromBinary. Instead of returning the original diacritic characters (like é, Ã, á), it returns a question mark (?) wherever it encounters such a character.
// Output: "Guillermo St?bile"
let
toBinary = Text.ToBinary( "Guillermo Stábile", 1361 ),
toText = Text.FromBinary( toBinary )
in
toText
You can use this method to identify how many diacritic characters are in a string and their positions, based on where the question marks appear in the output.
// Output of toText = "Fl?ri?n Albert"
// Output of Positions = { 2, 5 }
let
toBinary = Text.ToBinary( "Flórián Albert", 1361 ),
toText = Text.FromBinary( toBinary ),
Positions = Text.PositionOfAny( toText , { "?" }, Occurrence.All )
in
Positions
In this example, “Flórián Albert” is converted, and diacritic characters are replaced with question marks (?). The Text.PositionOfAny function can then help you find the positions of diacritics in the text.
Related functions
Other functions related to Text.ToBinary are:
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy