Type.Is

D

T

The M Code Behind the Power Query M function Type.Is

In this article, we will explore the M code behind the Type.Is function and how it can be used in Power Query.

What is the Type.Is Function?

The Type.Is function is a built-in function in Power Query that allows users to check the data type of a column or value in a table. The function takes two arguments: the first argument is the column or value to check, and the second argument is the data type to check for.

The syntax of the Type.Is function is as follows:


Type.Is(value as any, type as type) as logical


The first argument, value, can be any column or value in the table. The second argument, type, is a data type that you want to check for. The function returns a logical value of true or false, depending on whether the value matches the specified data type.

How to Use the Type.Is Function

To use the Type.Is function, follow these steps:

1. Open Power Query and connect to your data source.

2. Select the column or value that you want to check.

3. Click on the Add Column tab in the ribbon.

4. Click on the Custom Column button.

5. In the Custom Column dialog box, enter a name for the new column.

6. In the Custom Column dialog box, enter the following formula:


= Type.Is([ColumnName], type)


Replace [ColumnName] with the name of the column that you want to check, and replace type with the data type that you want to check for.

For example, if you want to check whether a column contains dates, you can use the following formula:


= Type.Is([DateColumn], type date)


7. Click OK to create the new column.

The M Code Behind the Type.Is Function

The Type.Is function is implemented using M code, which is the underlying language used by Power Query. The M code behind the Type.Is function is as follows:


let

Type.Is = (value as any, type as type) as logical =>

try Type.IsOf(value, type) otherwise false

in

Type.Is


The M code defines a function called Type.Is, which takes two arguments: value and type. The function uses the try function to check whether the value matches the specified data type. If the value matches the data type, the function returns true. Otherwise, the function returns false.

The Type.Is function uses the Type.IsOf function to check whether the value matches the specified data type. The Type.IsOf function is another built-in function in Power Query that returns true if the value matches the specified data type.

The Type.Is function is a powerful function in Power Query that allows users to check the data type of a column or value in a table. The function is implemented using M code, which is the underlying language used by Power Query. By using the Type.Is function, users can quickly and easily check the data type of a column or value, which can help to ensure data quality and accuracy.

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)