Function.IsDataSource

D

T

The M Code Behind the Power Query M function Function.IsDataSource

What is Function.IsDataSource?

Function.IsDataSource is a built-in function in Power Query M that checks whether the given input is a valid data source or not. It returns a boolean value of true if the input is a valid data source and false otherwise.

How does Function.IsDataSource work?

Function.IsDataSource works by validating the input against a set of rules. These rules are defined in the M code behind the function. Let’s take a look at the M code behind Function.IsDataSource and understand how it works.


let

isDataSource = (input as any) =>

let

dataSource = if Type.Is(input, type table) then input else null,

validDataSource = if dataSource <> null and Record.HasFields(dataSource, { “Data”, “Columns” }) then dataSource else null

in

validDataSource <> null

in

isDataSource


The M code for Function.IsDataSource contains a nested function called isDataSource that takes an input parameter of any data type. The first step in the function is to check whether the input is of type table. If the input is not of type table, the dataSource variable is set to null.

If the input is of type table, the dataSource variable is set to the input. The next step is to check whether the dataSource variable is null or not. If it is null, the validDataSource variable is also set to null.

If the dataSource variable is not null, the next step is to check whether it has the required fields - "Data" and "Columns". If the dataSource variable has these fields, it is considered a valid data source and the validDataSource variable is set to the dataSource variable. If the dataSource variable does not have these fields, the validDataSource variable is set to null.

Finally, the function returns true if the validDataSource variable is not null and false otherwise. This means that if the input is a valid data source, the Function.IsDataSource function will return true. If the input is not a valid data source, the function will return false.

In this article, we took a deep dive into the M code behind the Function.IsDataSource function in Power Query M. We learned that the function works by validating the input against a set of rules defined in the M code. If the input is a valid data source, the function returns true. If the input is not a valid data source, the function returns false. Understanding how this function works is important when working with Power Query M, especially when dealing with complex data sources.

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)