Table.PositionOfAny
TableReturns the first position of any row in the table that matches any record in the given list.
Syntax
Table.PositionOfAny(table as table, rows as list, optional occurrence as nullable number, optional equationCriteria as any) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to search. |
rows | list | Yes | A list of records to search for. |
occurrence | number | No | Optional. Use Occurrence.First (0), Occurrence.Last (1), or Occurrence.All (2) to control which positions are returned. |
equationCriteria | any | No | Optional. Column name(s) or comparer to restrict which fields are compared. |
Return Value
any — A row index, a list of row indices, or -1 if no match is found.
Remarks
Table.PositionOfAny is the multi-candidate variant of Table.PositionOf. Instead of searching for a single record, it accepts a list of candidate records and returns the position of the first row in the table that matches any of them. If no candidate matches any row, it returns -1.
The occurrence parameter controls the return behavior:
- Occurrence.First (default): the index of the first row matching any candidate.
- Occurrence.Last: the index of the last row matching any candidate.
- Occurrence.All: a list of all row indices that match any candidate.
The optional equationCriteria parameter restricts which columns are compared, enabling partial record matching across all candidates simultaneously. This function is useful when you have a set of "sentinel" or "anchor" rows whose positions you need to locate, for example to determine slice boundaries in a structured flat file.
Examples
Example 1: Find the first position of any of several customers
let
Sales = #table(
{"OrderID", "CustomerName", "Product"},
{{1,"Alice","Widget A"},{2,"Bob","Gadget B"},{3,"Charlie","Widget C"},{4,"Diana","Gadget D"}}
),
Targets = {[CustomerName = "Charlie"], [CustomerName = "Diana"]}
in
Table.PositionOfAny(Sales, Targets, Occurrence.First, "CustomerName")Result | |
|---|---|
| 1 | 2 |
Example 2: No candidate matches — returns -1
let
Products = #table(
{"ProductName"},
{{"Widget A"},{"Gadget B"},{"Widget C"}}
),
Searches = {[ProductName = "Thingamajig E"], [ProductName = "Widget Z"]}
in
Table.PositionOfAny(Products, Searches, Occurrence.First, "ProductName")Result | |
|---|---|
| 1 | -1 |
Example 3: Return all positions matching any of the target customers
let
Sales = #table(
{"OrderID", "CustomerName"},
{{1,"Alice"},{2,"Bob"},{3,"Alice"},{4,"Charlie"},{5,"Diana"},{6,"Bob"},{7,"Alice"}}
),
Targets = {[CustomerName = "Alice"], [CustomerName = "Bob"]}
in
Table.PositionOfAny(Sales, Targets, Occurrence.All, "CustomerName")Result | |
|---|---|
| 1 | {0, 1, 2, 5, 6} |