Table.HasColumns

Updated on

Table.HasColumns is a Power Query M function that indicates whether a table contains the specified column(s). The function returns true if the table contains the column(s), and false otherwise.

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

Syntax

Table.HasColumns(
   table as table,
   columns as any,
) as logical

Description

Table.HasColumns indicates whether the table contains specific columns, columns. Returns true if it contains the columns, false otherwise.

Examples

Determine if the table has the column [Name].

// Output: true
Table.HasColumns( 
    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"
 )

Find if the table has the column [Name] and [PhoneNumber].

// Output: false
Table.HasColumns( 
    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", "PhoneNumber"}
 )

Other functions related to Table.HasColumns are:

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