Table.Contains

Updated on

Table.Contains is a Power Query M function that checks if a specified record appears as a row in the table, with an optional parameter to control comparison between rows. The function returns a logical value indicating the presence of the record.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Table.Contains(
   table as table,
   row as record,
   optional equationCriteria as any,
) as logical
ArgumentAttributeDescription
tableThe table to check.
rowThe row values in to look for specified as a record value.
equationCriteriaoptionalUses Comparer Functions to determine how values are equated during operations. Options include Comparer.Ordinal for exact case-sensitive matching, Comparer.OrdinalIgnoreCase for case-insensitive matching, and Comparer.FromCulture for culture-specific comparisons.

Description

Table.Contains checks if a specified record, row, appears as a row in table. An optional equationCriteria can be used for row comparison.

Examples

Determine if the table contains the row.

// Output: true
Table.Contains( 
    Table.FromRecords( {
        [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
        [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
        [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
        [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
    } ),
    [Name = "Bob"]
 )

Determine if the table contains the row.

// Output: false
Table.Contains( 
    Table.FromRecords( {
        [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
        [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
        [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
        [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
    } ),
    [Name = "Ted"]
 )

Determine if the table contains the row comparing only the column [Name].

// Output: true
Table.Contains( 
    Table.FromRecords( {
        [CustomerID = 1, Name = "Bob", Phone = "123-4567"],
        [CustomerID = 2, Name = "Jim", Phone = "987-6543"],
        [CustomerID = 3, Name = "Paul", Phone = "543-7890"],
        [CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
    } ),
    [CustomerID = 4, Name = "Bob"],
    "Name"
 )

Learn more about Table.Contains in the following articles:

Other functions related to Table.Contains are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-contains