Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Value.FromText Function: A Complete Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Value.FromText function in Power Query (M language) converts a text string into a specific data type, such as a number, date, or logical value, based on the content of the string. To use it, you simply wrap the text or the column reference in the function: Value.FromText([ColumnName]). This function is essential when you have data that is technically stored as text but represents a value that requires mathematical or chronological operations.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • Access to the Power Query Editor (Get Data > Launch Power Query Editor).
  • A dataset containing text columns that represent numbers, dates, or booleans.
  • Basic familiarity with adding a Custom Column in the Power Query interface.

Step-by-Step

  1. Open Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
  2. Identify the Target Column: Locate the column containing the text values you wish to convert. Ensure the column is currently set to the "Text" data type (indicated by the "ABC" icon next to the column header).
  3. Add a Custom Column: Navigate to the Add Column tab on the top ribbon and select Custom Column. This opens the Custom Column dialog box where you can enter your M formula.
  4. Enter the Function: In the Custom column formula box, type = Value.FromText([YourColumnName]). Replace [YourColumnName] by double-clicking the actual column name from the list of available columns on the right side of the dialog box.
  5. Define Culture (Optional): If your text uses regional formatting (for example, a comma as a decimal separator in Europe vs. a period in the US), you can add a second argument to the function: = Value.FromText([YourColumnName], "en-US") or "de-DE". This tells Power Query which regional rules to apply when interpreting the text.
  6. Validate the Result: Click OK. A new column will appear. Power Query will attempt to automatically detect the resulting type, but you should manually verify it by clicking the data type icon in the column header and selecting the correct type (e.g., Decimal Number, Whole Number, or Date).
  7. Remove Original Column: Once you have verified that the conversion is accurate, right-click the original text column and select Remove to clean up your dataset.

Common Mistakes

One of the most frequent errors is attempting to use Value.FromText on a cell that contains non-numeric characters when a number is expected. For example, if a cell contains "$1,200", the currency symbol and comma may cause the function to return an error depending on the locale settings. The function expects a clean representation of the value it is trying to create.

Another common mistake is forgetting that Value.FromText is distinct from simply changing the data type via the UI. While changing the type via the UI is often sufficient, Value.FromText is used within custom M code or complex conditional columns where you need to programmatically handle the conversion during a specific step of the transformation process.

Users also frequently overlook the "Culture" argument. If you are processing a CSV file generated in a different country, a date formatted as "DD/MM/YYYY" may be misinterpreted as "MM/DD/YYYY" or fail entirely if the day is greater than 12. Failing to specify the culture leads to inconsistent results across different machines running the same report.

Tips

To make your transformation more robust, combine Value.FromText with try...otherwise logic. This prevents the entire query from failing if a single row contains a malformed string. For example: try Value.FromText([Column]) otherwise null. This will replace any conversion errors with a null value, allowing you to filter or fix those specific rows later.

If your text contains symbols like currency signs, percent signs, or thousands separators that are not recognized by your local settings, use the Text.Replace or Text.Remove functions before applying Value.FromText. For instance, Value.FromText(Text.Replace([Price], "$", "")) ensures the function only sees the numeric part of the string.

For dates, while Value.FromText works, consider using Date.FromText if you know specifically that the output must be a date. Value.FromText is a generic converter, whereas the Date.FromText or Number.FromText functions provide more specialized control and are often easier to read for other developers auditing your M code.

Troubleshooting

If you encounter an Expression.Error: We cannot convert the value... to type..., the first step is to check for hidden characters. Often, text imported from web sources contains non-breaking spaces or invisible control characters. Use the Text.Trim function around your column reference: Value.FromText(Text.Trim([Column])).

If the function returns a value but the date or number looks wrong (e.g., January 5th becoming May 1st), this is a locale issue. Check your Global and Current Workbook settings in Excel (File > Options > Data) or the Power BI file settings. If the settings are correct but the data is from a different region, explicitly define the culture in the function as Value.FromText([Column], "culture-code").

When the function returns Error for a large number of rows, create a temporary column using Text.Length([Column]) to see if there are trailing spaces or unexpected characters that are making the string "non-numeric" in the eyes of the engine. If the length is longer than the visible characters, a trim is necessary.

Frequently Asked Questions

How is Value.FromText different from changing the data type in the ribbon?

Changing the type in the ribbon creates a Table.TransformColumnTypes step that applies to the whole column. Value.FromText is a function used within a custom column or a formula to convert a single value, providing more flexibility for conditional logic.

Can Value.FromText handle boolean (True/False) values?

Yes, if the text string is "true" or "false" (case-insensitive), Value.FromText will convert it into a logical boolean value that Power Query can use for filtering and conditional logic.

Does this function work with scientific notation?

Yes, Value.FromText can typically recognize and convert strings in scientific notation (e.g., "1.2E+04") into their corresponding decimal number values.

What happens if the input is already a number?

If you pass a value that is already a number or a date into Value.FromText, the function will return an error because it specifically expects a text string as its first input. You can wrap the input in Text.From() to ensure it is text before converting it back.

Can I use this to convert Unix timestamps?

Not directly. Value.FromText will convert the Unix timestamp string into a large number, but you will still need to use #datetime functions to convert that number into a readable date and time format.