Logical.From

Logical.From

D

The M Code Behind the Power Query M function Logical.From

What is Logical.From?

The Logical.From function is a relatively simple M function that converts a boolean value to a text value. For example, if the input value is true, the output value will be “true”. Similarly, if the input value is false, the output value will be “false”.

The M Code Behind Logical.From

The M code behind Logical.From is relatively simple. Here’s the code in its entirety:


let

Logical.From = (value as logical) as text =>

if value then “true” else “false”

in

Logical.From


The code defines a function called Logical.From that takes a single input parameter, "value". The function then uses an "if" statement to check whether the input value is true or false. If the input value is true, the function returns the text value "true". If the input value is false, the function returns the text value "false".

How to Use Logical.From

Using Logical.From is relatively simple. To use the function in your Power Query code, you simply need to call the function and pass in a boolean value. Here's an example:


let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(“i45WMjIwMjEA”, BinaryEncoding.Base64)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t])),

#”Changed Type” = Table.TransformColumnTypes(Source,{{“Column1”, type logical}}),

#”Added Custom” = Table.AddColumn(#”Changed Type”, “Logical Value”, each Logical.From([Column1]))

in

#”Added Custom”


In this example, we start by defining a data source using the Table.FromRows function. We then use the Table.TransformColumnTypes function to convert the "Column1" column to a logical data type. Finally, we use the Table.AddColumn function to add a new column called "Logical Value", which uses the Logical.From function to convert the values in the "Column1" column to text values.

In this article, we've taken a closer look at the M code behind the Power Query M function Logical.From. We've seen that the code is relatively simple, using an "if" statement to check whether the input value is true or false. We've also seen how to use the function in a Power Query script. Logical.From is a powerful tool that can help you clean and reshape data quickly and easily in Power Query.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

Subject

Your Name (required)

Company/Organisation

Email (required)

Telephone

Training Course(s)

Your Message

Upload Example Document(s) (Zip multiple files)

Copyright, G Com Solutions Ltd, 2024.
Tower Bridge Business Centre, 46-48 East Smithfield, London E1W 1AW
0800 998 9248   |   9:00 a.m. till 5:30 p.m.

Connect With Me: