Logical.From

Updated on

Logical.From is a Power Query M function that converts a given value to a logical value, handling null values, text, and numbers. The function returns the converted logical value, or an error if the input value cannot be converted.

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

Syntax

Logical.From( value as any ) as nullable logical

Description

The Logical.From function converts various types of values into their corresponding boolean (true/false) equivalents in Power Query M. This function handles text, number, and null values, providing a consistent method for interpreting Boolean values. The following types are supported:

  • Text: Converts “true” to true and “false” to false.
  • Number: Converts 0 to false and any other number to true.
  • Null: Returns null

Providing any other type of value will result in an error.

Examples

Let’s explore several examples demonstrating how the Logical.From function works.

Converting Text Values to Boolean

When working with text values you can turn them into their boolean equivalents. For a string representing a true value, such as "true", the conversion is straightforward:

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

In this example, the string "true" is converted to the boolean value true.

Similarly, a string representing a false value, such as "false", is converted as follows:

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

Here, the string "false" is converted to the boolean value false.

Converting Number Values to Boolean

The Logical.From function can also convert numerical values into their corresponding boolean equivalents. The number 0 is always converted to the boolean value false.

Logical.From( 0 ) // Output: false

Any number other than zero is converted to the boolean value true. Here are some examples:

Logical.From( 1 )     // Output: true
Logical.From( 150 )   // Output: true
Logical.From( -1 )    // Output: true
Logical.From( -2999 ) // Output: true

In each of these cases, regardless of whether the number is positive or negative, the Logical.From function returns true.

Handling Null Values

Finally, the function can also handle ‘null’ values. In those cases, it will return null:

Logical.From( null ) // Output: null

Other functions related to Logical.From are:

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

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