OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to search.
rowrecordThe row to look for, as a record of column names and values.
occurrenceany
optional
Occurrence.First (the default), Occurrence.Last or Occurrence.All.
equationCriteriaany
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.Range and table{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

Table.Contains, List.PositionOf, Table.Range, Table.SelectRows.

Last updated · OpenBI Studio 0.3.79