Table.HasColumns

Table

Returns true if a table contains the specified column or columns.

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

Syntax

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

Parameters

NameTypeRequiredDescription
tabletableYesThe table to check.
columnsanyYesA column name (text) or a list of column names to check for.

Return Value

logicaltrue if all specified columns exist in the table, false otherwise.

Remarks

Table.HasColumns checks whether a table contains one or more specified columns. When given a list of column names, it returns true only if all columns exist. This is useful for writing defensive queries that adapt to tables with varying schemas — for example, conditionally adding a step only when a certain column is present.

Examples

Example 1: Check for a single column

let
    HasRegion = Table.HasColumns(Sales, "Region")
in
    #table({"HasRegion"}, {{HasRegion}})
Result
HasRegion
1TRUE

Example 2: Check for a missing column

let
    HasDiscount = Table.HasColumns(Sales, "Discount")
in
    #table({"HasDiscount"}, {{HasDiscount}})
Result
HasDiscount
1FALSE

Compatibility

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