Table.IsEmpty

D

T

The M Code Behind the Power Query M function Table.IsEmpty

The Table.IsEmpty function returns true if the table is empty or false if it contains data. In this article, we will discuss the M code behind this function and how it can be used in Power Query.

Understanding Table.IsEmpty Function

The Table.IsEmpty function is used to determine whether a table contains data or not. It takes a table as an argument and returns a boolean value. The function returns true if the table is empty and false if it contains data.

The M code behind the Table.IsEmpty function is as follows:


(Table as table) =>

let

Source = Table.RowCount(Table.SelectRows(Table.Distinct(Table.Buffer(Table)), each true)),

Result = if Source = 0 then true else false

in

Result


Breaking Down the M Code

Let’s break down the M code behind the Table.IsEmpty function and understand how it works.

The first line of the M code `(Table as table) =>` is the function signature. It defines the input argument `Table` as a table.

The second line `let` starts a new block of code. This block of code is used to declare variables and create expressions.

The third line `Source = Table.RowCount(Table.SelectRows(Table.Distinct(Table.Buffer(Table)), each true))` creates a variable called `Source`. This variable counts the number of rows in the table and selects the rows that are not empty. This is done by using the Table.SelectRows function with the `each true` condition.

The fourth line `Result = if Source = 0 then true else false` creates a variable called `Result`. This variable determines whether the table is empty or not. If the `Source` variable is equal to 0, it means that the table is empty and the function returns true. Otherwise, the function returns false.

The final line `in Result` is used to return the value of the `Result` variable.

Using Table.IsEmpty Function in Power Query

The Table.IsEmpty function can be used in various scenarios in Power Query. For example, it can be used to check whether a table loaded from a data source is empty or not. If the table is empty, the function can be used to alert the user to the fact and prompt them to take action.

The function can also be used in a conditional column to create a new column that indicates whether a given row in a table is empty or not. This is done by adding a new column and using the Table.IsEmpty function in an if statement.

In conclusion, the Table.IsEmpty function is a useful function in Power Query that helps to determine whether a table contains data or not. The M code behind the function shows how it works by counting the number of rows in the table and selecting the rows that are not empty. The function can be used in various scenarios in Power Query, such as checking whether a table loaded from a data source is empty or creating a new column that indicates whether a given row in a table is empty or not.

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)