Table.HasColumns
TableReturns true if a table contains the specified column or columns.
Syntax
Table.HasColumns(table as table, columns as any) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The table to check. |
columns | any | Yes | A column name (text) or a list of column names to check for. |
Return Value
logical — true 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 | |
|---|---|
| 1 | TRUE |
Example 2: Check for a missing column
let
HasDiscount = Table.HasColumns(Sales, "Discount")
in
#table({"HasDiscount"}, {{HasDiscount}})Result
HasDiscount | |
|---|---|
| 1 | FALSE |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks