Smart Systems for Home

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

Power Query Logical.From Function: Step-by-Step 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

Logical.From converts a value to a logical (true/false) type in Power Query. It is useful when a column contains text like "true" or "false", numbers like 1 and 0, or mixed values, and you need a proper boolean for filtering, comparisons, or when loading to the data model. To use it, you need Power Query available in Excel, Power BI, or another supported host, and a query with at least one column to convert. The function takes a value and an optional culture argument, and it returns true or false, or null if the value cannot be converted.

What You'll Need

  • Power Query Editor open in Excel (Data > Get & Transform Data) or Power BI (Transform data). Menu labels can differ slightly by version and platform.
  • A query with a column that contains values you want to turn into logicals, such as text "true"/"false", "yes"/"no", or numbers 1/0.
  • Basic familiarity with adding a custom column or editing the formula bar.
  • A backup of your workbook or report, since query changes affect the loaded data.

Step-by-Step

  1. Open the Power Query Editor. In Excel, select your data and go to Data > Get & Transform Data > From Table/Range. In Power BI Desktop, choose Home > Transform data. The editor opens with your query selected.
  2. Locate the column you want to convert. In the Queries pane on the left, click the query, then find the column in the data preview. Note its exact name, including spaces and capitalization.
  3. Add a custom column. On the Home tab, click Add Column > Custom Column. In the dialog, give the new column a name, such as "IsActiveLogical".
  4. Enter the formula. In the Custom Column formula box, type Logical.From([YourColumnName]), replacing YourColumnName with the actual column name. If your column name contains spaces, wrap it in square brackets and use the exact name, for example Logical.From([Is Active]). If you need to handle a specific culture, add it as a second argument in quotes, such as Logical.From([TextValue], "en-US").
  5. Click OK. Power Query adds the new column and shows the converted values. True and false appear as logical values; values it cannot interpret become null or raise an error, depending on the input.
  6. Check the results. Scroll through the new column. If you see errors, select the error cell to read the message. Common issues are text that is not a recognized boolean string or numbers other than 1 and 0.
  7. Clean up if needed. If you want to replace the original column, you can remove it (right-click the column header > Remove) or keep both. To change the column type explicitly, select the new column and use the data type icon in the column header to set it to True/False.
  8. Apply and close. In Excel, click Home > Close & Load to load the query to a worksheet or the data model. In Power BI, click Home > Close & Apply. The converted logical column is now available for filtering, relationships, and measures.

Common Mistakes

  • Using the wrong column name in the formula. Column names are case-sensitive in M and must match exactly, including spaces. Use the column name from the query, not the header text if it differs.
  • Forgetting to wrap column names with spaces in square brackets. Logical.From([My Column]) is correct; Logical.From(My Column) is not.
  • Expecting Logical.From to convert arbitrary text like "yes" or "no". It recognizes standard boolean representations such as "true" and "false" (and their case variants), and numeric 1 and 0. For other text, you may need to add a conditional step first.
  • Assuming errors are always visible. Some invalid conversions return null rather than an error, which can silently affect downstream calculations. Check for nulls after conversion.
  • Applying the function to an entire table instead of a column. Logical.From works on a single value, so use it inside a custom column or a transformation that operates row by row.

Tips

  • Use the formula bar to edit the step if you prefer. Select the step in the Applied Steps pane and adjust the M code directly.
  • If your source uses "Yes"/"No" or "Y"/"N", add a conditional column or use a replace values step to convert them to "true"/"false" before applying Logical.From.
  • To handle nulls gracefully, wrap the call in try ... otherwise null, for example try Logical.From([Column]) otherwise null. This prevents errors from breaking the query.
  • After conversion, set the column data type to True/False explicitly. This helps Power Query and the data model treat it as boolean rather than any.
  • If you need to convert back to text, use Text.From on the logical column.

Troubleshooting

If the new column shows errors, click the error cell to see the message. A common message is that the value could not be converted to type Logical. Check the original value: it may be blank, contain extra spaces, or use a word other than true/false. Trim and clean the text first, or use a conditional replacement.

If the column shows null instead of true/false, the value was not recognized. Verify the exact spelling and case. Logical.From is not case-sensitive for "true" and "false", but it does not accept "yes" or "no".

If the function is not recognized, ensure you are using it in a context that supports M functions, such as a custom column or advanced editor. In Excel, Power Query is built-in from Excel 2016 onward; older versions may need the Power Query add-in.

If the query is slow, check whether you are applying Logical.From to a large column unnecessarily. You can often set the column type directly instead of adding a custom column, which is simpler and faster.

Frequently Asked Questions

What does Logical.From do in Power Query?

It converts a value to a logical type (true or false). It is typically used to turn text or numeric representations of booleans into a proper boolean column.

Can Logical.From convert "Yes" or "No" to true/false?

No. It recognizes standard boolean strings such as "true" and "false", and numeric 1 and 0. For other words, add a conditional column or replace values step first.

What happens if the value cannot be converted?

Depending on the input, Logical.From may return null or raise an error. You can handle errors with try ... otherwise to return a default value.

Is Logical.From case-sensitive?

It accepts "true" and "false" in any case, such as "True" or "FALSE". Other text is not converted.

Do I need a specific version of Excel or Power BI?

Logical.From is part of the M language available in Power Query for Excel 2016 and later, and in Power BI Desktop. Menu labels may vary slightly by version.

Can I use Logical.From on a whole column at once?

No, it operates on a single value. Use it inside a custom column to apply it row by row, or change the column data type directly if the values are already recognizable.