Table.PositionOf
Where a row is in a table, counting from 0: the first match, the last one, or all of them.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.PositionOf(table as table, row as record, optional occurrence as any, optional equationCriteria as any) as any
| Parameter | Type | Description |
|---|---|---|
table | table | The table to search. |
row | record | The row to look for, as a record of column names and values. |
occurrence | any optional | Occurrence.First (the default), Occurrence.Last or Occurrence.All. |
equationCriteria | any optional | The columns that decide a match, as a name or a list of names. |
Returns
any. A position, or -1 when no row matches; with Occurrence.All, a list of positions.
Remarks
- Positions count from 0, as in
Table.Rangeandtable{0}. - Give the whole row as the record, or name in equationCriteria the columns that count.
Examples
Where a row is
let
Stock = #table({"Shop", "Product"}, {{"Oslo", "Chair"}, {"Bergen", "Desk"}, {"Oslo", "Desk"}})
in
Table.PositionOf(Stock, [Shop = "Bergen", Product = "Desk"])
1
Every row of one shop
let
Stock = #table({"Shop", "Product"}, {{"Oslo", "Chair"}, {"Bergen", "Desk"}, {"Oslo", "Desk"}})
in
Table.PositionOf(Stock, [Shop = "Oslo"], Occurrence.All, "Shop")
{0, 2}
A row that isn't there
let
Stock = #table({"Shop", "Product"}, {{"Oslo", "Chair"}, {"Bergen", "Desk"}})
in
Table.PositionOf(Stock, [Shop = "Tromsø", Product = "Lamp"])
-1
Related functions
Table.Contains, List.PositionOf, Table.Range, Table.SelectRows.