Table.InsertRows

D

T

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

Syntax of the Table.InsertRows Function

The `Table.InsertRows` function has the following syntax:


Table.InsertRows(table as table, insert as list, optional options as nullable record) as table


The function takes three arguments:

– `table` – the table that you want to add the rows to

– `insert` – a list of rows that you want to add to the table

– `options` – an optional record that specifies additional options for the function

How to Use the Table.InsertRows Function

To use the `Table.InsertRows` function in Power Query, you first need to create a query that returns the table that you want to add rows to. You can do this by using the `From Table` option in the `From Other Sources` dropdown in the `Home` tab of the Power Query Editor.

Once you have the table loaded into Power Query, you can use the `Table.InsertRows` function in a subsequent step to add rows to the table. To do this, you need to create a list of records that represent the rows that you want to add to the table.

Here is an example of how to use the `Table.InsertRows` function to add a single row to a table:


let

Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

NewRow = [Column1="NewValue1", Column2="NewValue2"],

InsertedRows = Table.InsertRows(Source, {NewRow})

in

InsertedRows


In this example, we first load the table into Power Query using the `Excel.CurrentWorkbook` function. We then create a new record that represents the row that we want to add to the table. Finally, we use the `Table.InsertRows` function to add the new row to the table.

Adding Multiple Rows to a Table

You can also use the `Table.InsertRows` function to add multiple rows to a table. To do this, you need to create a list of records that represent the rows that you want to add to the table.

Here is an example of how to use the `Table.InsertRows` function to add multiple rows to a table:


let

Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

NewRows = {

[Column1="NewValue1", Column2="NewValue2"],

[Column1="NewValue3", Column2="NewValue4"]

},

InsertedRows = Table.InsertRows(Source, NewRows)

in

InsertedRows


In this example, we create a list of records that represent the two rows that we want to add to the table. We then use the `Table.InsertRows` function to add the new rows to the table.

The `Table.InsertRows` function in Power Query is a powerful tool that allows you to dynamically add rows to a table. By understanding the M code behind this function, you can manipulate data in Power Query in a more efficient and effective way.

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)