Logical.FromText

Updated on

Logical.FromText is a Power Query M function that creates a logical value from a case-insensitive text value, either “true” or “false”. The function returns the created logical value or throws an exception if the text contains a different string.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Logical.FromText( text as nullable text ) as nullable logical

Description

The Logical.FromText function is designed to convert text values into their boolean (true/false) equivalents. This function only supports the text strings “true” and “false” as valid inputs. Any other value will result in an error. Remember that the function ignores case.

Examples

Let’s look at some examples of how to put this function to use.

Converting “true” to Boolean

When the input text is “true”, the Logical.FromText function converts it to the boolean value true:

Logical.FromText( "true" ) // Output: true

The function is case insensitive, so variations in capitalization still return the same result:

Logical.FromText( "TRUE" ) // Output: true
Logical.FromText( "TruE" ) // Output: true

Converting “false” to Boolean

Similarly, when the input text is “false”, the function converts it to the boolean value false:

Logical.FromText( "false" ) // Output: false

Just like with “true”, the function accepts different capitalizations of “false”:

Logical.FromText("FALSE") // Output: false
Logical.FromText("FaLsE") // Output: false

Invalid Text Input

If the input text is anything other than “true” or “false”, the function will result in an error. Examples of invalid inputs include:

Logical.FromText("yes") // "Expression.Error: We couldn't convert to Logical."
Logical.FromText("no")  //  "Expression.Error: We couldn't convert to Logical."
Logical.FromText("123") // "Expression.Error: We couldn't convert to Logical."

Other functions related to Logical.FromText are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/logical-fromtext

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy