OpenBI Docs Buy

Table.Partition

Shares a table's rows out over a set number of tables, by a number worked out from one column's value.

Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Table.Partition(table as table, column as text, groups as number, hash as function) as list
ParameterTypeDescription
tabletableThe rows to share out.
columntextThe column whose value decides where each row goes.
groupsnumberHow many tables to make.
hashfunctionA function of the column's value that gives a whole number: what is left after dividing it by groups is the row's table, counting from 0.

Returns

list. A list of groups tables with the table's columns; a table no row went to is empty.

Remarks

  • Rows keep their order inside each table.
  • Rows with the same value always land in the same table, so each table can be worked on without the others.

Examples

Orders in three parts by order number

let
    Orders = #table({"Order", "Product"}, {{101, "Chair"}, {102, "Desk"}, {103, "Lamp"}, {104, "Sofa"}, {105, "Shelf"}})
in
    Table.Partition(Orders, "Order", 3, each _)
{Table.FromRecords({[Order = 102, Product = "Desk"], [Order = 105, Product = "Shelf"]}), Table.FromRecords({[Order = 103, Product = "Lamp"]}), Table.FromRecords({[Order = 101, Product = "Chair"], [Order = 104, Product = "Sofa"]})}

102 and 105 leave 0 when divided by 3, so they make the first table; 103 leaves 1; 101 and 104 leave 2.

Table.Split, Table.Group, Table.SplitAt, Table.Combine.

Last updated · OpenBI Studio 0.3.79