Table.ContainsAny

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

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

Syntax

Table.ContainsAny(
   table as table,
   rows as list,
   optional equationCriteria as any,
) as logical
ArgumentAttributeDescription
tableThe table to search.
rowsA list of record values to search for.
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

Indicates whether any the specified records in the list of records rows, appear as rows in the table. An optional parameter equationCriteria may be specified to control comparison between the rows of the table.

Examples

Determine if the table ( {[a = 1, b = 2], [a = 3, b = 4]} ) contains the rows [a = 1, b = 2] or [a = 3, b = 5].

// Output: true
Table.ContainsAny( 
    Table.FromRecords( {
        [a = 1, b = 2],
        [a = 3, b = 4]
    } ),
    {
        [a = 1, b = 2],
        [a = 3, b = 5]
    }
 )

Determine if the table ( {[a = 1, b = 2], [a = 3, b = 4]} ) contains the rows [a = 1, b = 3] or [a = 3, b = 5].

// Output: false
Table.ContainsAny( 
    Table.FromRecords( {
        [a = 1, b = 2],
        [a = 3, b = 4]
    } ),
    {
        [a = 1, b = 3],
        [a = 3, b = 5]
    }
 )

Determine if the table ( Table.FromRecords( {[a = 1, b = 2], [a = 3, b = 4]} ) ) contains the rows [a = 1, b = 3] or [a = 3, b = 5] comparing only the column [a].

// Output: true
Table.ContainsAny( 
    Table.FromRecords( {
        [a = 1, b = 2],
        [a = 3, b = 4]
    } ),
    {
        [a = 1, b = 3],
        [a = 3, b = 5]
    },
    "a"
 )

Other functions related to Table.ContainsAny are:

BI Gorilla Blog

Last update: August 25, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-containsany
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.