Power Query Text.FromBinary Function Guide
In this article
The Text.FromBinary function in Power Query is used to convert a binary value—such as the contents of a file, a web response, or a database blob—into a readable text string. To use it, you wrap the binary source in the function and specify the text encoding (like UTF-8) to ensure characters are rendered correctly. This is essential when you are importing raw data from APIs or reading flat files where Power Query does not automatically detect the format.
What You'll Need
- Microsoft Excel or Power BI Desktop.
- A data source that provides binary data (e.g., a .txt file, a .csv file, or a Web.Contents API call).
- Access to the Power Query Editor (Get Data > Launch Power Query Editor).
Step-by-Step
- Access the Power Query Editor: Open your application and navigate to the Data tab. Select Get Data and choose your source. If you are already in a query, ensure you are in the Power Query Editor window.
- Identify the Binary Column: Look for a column that contains the value "Binary". This typically happens when you import a folder of files or use
Web.Contents. The cell will literally say "Binary" in italicized text. - Create a Custom Column: Go to the Add Column tab on the top ribbon and select Custom Column. This allows you to apply the function to every row in your binary column.
- Enter the Formula: In the Custom Column formula box, type the following:
Text.FromBinary([YourBinaryColumnName]). Replace[YourBinaryColumnName]with the actual name of the column containing your binary data. - Specify the Encoding (Optional but Recommended): To avoid character corruption (like strange symbols appearing where accents or emojis should be), add the encoding argument. The most common is
TextEncoding.Utf8. The formula should look like this:Text.FromBinary([YourBinaryColumnName], TextEncoding.Utf8). - Validate the Result: Click OK. A new column will appear containing the decoded text. You can now see the actual content of the binary file or stream.
- Clean Up: Right-click the original binary column and select Remove to keep your dataset lean. You can then use the Split Column or Transform tools to parse the resulting text into a table.
Common Mistakes
One of the most frequent errors is forgetting to specify the encoding. While Power Query attempts to guess the encoding, it often defaults to a standard that may not match your source data, leading to "mojibake" (distorted text). Always explicitly define TextEncoding.Utf8 or TextEncoding.Windows depending on the source.
Another common mistake is attempting to use Text.FromBinary on a column that is already text. This function specifically requires a binary input. If you apply it to a text column, Power Query will return an error because the input type is mismatched. Always check the icon to the left of the column header; it should show a small binary icon (a series of blocks) rather than the "ABC" text icon.
Users also frequently confuse Text.FromBinary with Csv.Document. While Csv.Document also takes binary as an input, it automatically parses the text into rows and columns. Text.FromBinary simply gives you one long string of text. If you need a table, Csv.Document is the better choice; if you need the raw text for custom parsing or regex-style cleaning, Text.FromBinary is the correct tool.
Tips
When dealing with very large binary files, be mindful of memory usage. Converting a massive binary blob into a single text string can consume significant RAM. If the file is too large, consider using Binary.Range to extract only the portion of the binary data you need before converting it to text.
If you are unsure which encoding to use, try TextEncoding.Utf8 first, as it is the global standard for web-based data. If you see strange characters in a file created on an older Windows machine, try TextEncoding.Windows (which refers to Windows-1252). You can quickly swap these in the formula bar to see which one renders the text correctly without having to recreate the custom column.
To make your queries more maintainable, avoid hard-coding the encoding if you have multiple files with different encodings. You can create a separate mapping table that lists the file name and its corresponding encoding, then merge that table into your main query and reference the encoding column dynamically within the Text.FromBinary function.
Troubleshooting
Issue: The result is a long string of nonsense characters.
This is almost always an encoding mismatch. Check if the source file is UTF-8, UTF-16, or ANSI. Change the second argument of the function to TextEncoding.Utf16 or TextEncoding.Windows to see if the text resolves. If you are pulling from a web API, check the API documentation for the "Content-Type" header to identify the correct charset.
Issue: Error message "We cannot convert the value to type Binary".
This means the column you are referencing is not actually binary. Check your previous steps. If you have already applied a transformation that converted the binary to text or a table, Text.FromBinary will fail. Go back to the step where the column still shows the "Binary" label.
Issue: The query is extremely slow or crashes (Out of Memory).
Converting large binary files to text strings creates a massive object in memory. To fix this, try to filter your rows to a smaller subset before applying the conversion. Alternatively, check if you can use Csv.Document or Json.Document, which are optimized for streaming binary data into structured formats rather than loading the entire file as a single text string.
Issue: Special characters (like © or ñ) are appearing as boxes or question marks.
This occurs when the encoding is partially correct but doesn't support the specific character set. Ensure you are using TextEncoding.Utf8 for international characters. If the data comes from a legacy system, you may need to identify the specific regional code page used by that system.
Frequently Asked Questions
What is the difference between Text.FromBinary and Csv.Document?
Text.FromBinary converts binary data into a single, continuous text string. Csv.Document converts binary data directly into a structured table by identifying delimiters like commas or tabs.
Can I use this function for PDF files?
No. PDF files are complex binary formats, not simple text files. Using Text.FromBinary on a PDF will result in a string of unreadable binary characters. Use the built-in PDF connector in Power Query instead.
Which encoding should I use for most web APIs?
The vast majority of modern web APIs use UTF-8. Therefore, TextEncoding.Utf8 is the most reliable choice for Web.Contents responses.
Does Text.FromBinary work with images?
It will technically run, but it will not produce a readable image or text. Images are binary data that must be rendered by an image viewer, not converted to a text string.
Can I use this function in a custom function?
Yes. You can wrap Text.FromBinary inside a custom Power Query function (using the (binaryValue) => ... syntax) to apply the same decoding logic across multiple different queries consistently.