Table.InsertRows
Puts new rows into a table at a position you give.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.InsertRows(table as table, offset as number, rows as list) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to add to. |
offset | number | Where the new rows go: 0 before the first row, the row count after the last. |
rows | list | The new rows as records, with the table's column names as their fields. |
Returns
table. The table with the new rows at that position.
Remarks
- An offset beyond the end of the table is an error.
- To add rows at the end,
Table.Combinewith a second table does the same.
Examples
A product in second place
let
Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
Table.InsertRows(Lines, 1, {[Product = "Sofa", Price = 400, Units = 1]})
| Product | Price | Units |
|---|---|---|
| Chair | 50 | 4 |
| Sofa | 400 | 1 |
| Desk | 120 | 1 |
| Lamp | 30 | 6 |
Two rows at the end
let
Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
Table.InsertRows(Lines, 3, {[Product = "Rug", Price = 80, Units = 2], [Product = "Shelf", Price = 60, Units = 3]})
| Product | Price | Units |
|---|---|---|
| Chair | 50 | 4 |
| Desk | 120 | 1 |
| Lamp | 30 | 6 |
| Rug | 80 | 2 |
| Shelf | 60 | 3 |
Related functions
Table.Combine, Table.ReplaceRows, Table.RemoveRows, Table.FromRecords.