Table.Contains

Table

Returns true if the table contains a row matching the given record.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Table.Contains(table as table, row as record, optional equationCriteria as any) as logical

Parameters

NameTypeRequiredDescription
tabletableYesThe table to search.
rowrecordYesA record whose fields are matched against table rows.
equationCriteriaanyNoOptional. A column name, list of column names, or comparer function to control which fields are compared.

Return Value

logicaltrue if the table contains a matching row; false otherwise.

Remarks

Table.Contains checks whether a table includes at least one row matching the provided record. By default, every field in the record is compared against the corresponding column. The optional equationCriteria parameter can restrict the comparison to specific columns, which is useful when you only care about partial matches (e.g., checking that a CustomerID exists regardless of other column values).

The equationCriteria parameter accepts a column name (text), a list of column names, or a comparer function. When restricting to specific columns, the record passed as row only needs to include fields for those columns — extra fields in the record are ignored.

For checking multiple rows at once, use Table.ContainsAll (all must be present) or Table.ContainsAny (at least one must be present). For retrieving matching rows rather than a boolean result, use Table.SelectRows. Note that Table.Contains does not fold to data sources, so for large source tables prefer Table.SelectRows with a count check when folding matters.

Examples

Example 1: Check whether a specific customer has placed an order

let
    Sales = #table(
        {"OrderID", "CustomerName", "Product"},
        {{1,"Alice","Widget A"},{2,"Bob","Gadget B"},{3,"Charlie","Widget C"}}
    )
in
    Table.Contains(Sales, [CustomerName = "Bob"], "CustomerName")
Result
Result
1TRUE

Example 2: Check for an exact row match (all fields)

let
    Sales = #table(
        {"CustomerName", "Product"},
        {{"Alice","Widget A"},{"Bob","Gadget B"},{"Diana","Widget A"}}
    )
in
    Table.Contains(Sales, [CustomerName = "Alice", Product = "Gadget B"])
Result
Result
1FALSE

Example 3: Guard a lookup before accessing a record

let
    Products = #table(
        {"ProductID", "ProductName", "Price"},
        {{1,"Widget A",25.00},{2,"Gadget B",50.00},{3,"Widget C",15.00}}
    ),
    SearchID = 99,
    Exists   = Table.Contains(Products, [ProductID = SearchID], "ProductID"),
    Result   = if Exists
               then Table.First(Table.SelectRows(Products, each [ProductID] = SearchID))[ProductName]
               else "Product not found"
in
    Result
Result
Result
1Product not found

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks