Type.TableColumn

Updated on

Type.TableColumn is a Power Query M function that retrieves the type of a specified column in a given table type. The function returns the type of the specified column within the input table type.

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

Syntax

Type.TableColumn(
   tableType as type,
   column as text,
) as type

Description

The Type.TableColumn function returns the data type of a specific column within a table type. It takes two inputs: a table type and the name of the column for which the data type needs to be determined. The function returns the data type of the specified column. In cases where the column type isn’t explicitly defined, it defaults to returning type any, indicating a flexible, generic data type.

Examples

Let’s see how that works in practice. Suppose you have a table type defined as follows:

type table [ Date = date, Amount = number ]

Determining Column Type in a Table Type

This example showcases how to identify the data type of a specific column in a table type. Consider a table type defined with Date and Amount columns, where Date is of type date and Amount is of type number.

To return what type the amount column has you can use the following expression:

// Output: type number
let
  myTableType = type table [ Date = date, Amount = number ],
  typeOfColumn = Type.TableColumn( myTableType, "Amount" )
in
  typeOfColumn

This expression returns the data type of the Amount column, which in this case is type number.

Handling Columns Without a Defined Type

In this example, we explore what happens when we use the Type.TableColumn function on a column that hasn’t been explicitly assigned a data type.

// Output: type any
let
  myTableType = type table [ Date = date, Amount ],
  typeOfColumn = Type.TableColumn( myTableType, "Amount" )
in
  typeOfColumn

Here, the Amount column does not have a predefined type. When the Type.TableColumn function is applied, it defaults to type any, indicating a generic data type.

Other functions related to Type.TableColumn are:

BI Gorilla Youtube Channel

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