Type.Union

Type

Returns the union of a list of types — the most general type that is compatible with all types in the list.

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

Syntax

Type.Union(types as list) as type

Parameters

NameTypeRequiredDescription
typeslistYesA list of type values whose union is computed.

Return Value

typeThe most general type compatible with all provided types.

Remarks

Type.Union computes the least upper bound of a list of types — the most specific type that is a supertype of all types in the list. In simpler terms, it returns the most general type to which all provided types are assignable.

Key behaviors:

- Type.Union({type number, type nullable number}) returns type nullable number — the nullable form is a supertype of the non-nullable form - Type.Union({type number, type text}) returns type any — since number and text share no common supertype more specific than any - Type.Union({type text, type text}) returns type text — identical types produce that type unchanged - Type.Union({}) with an empty list returns type none — the bottom type (a type with no inhabitants)

Type.Union is used in generic transformation functions that need to determine a compatible output type when merging values from multiple sources that may have different types. It is also useful in custom connector schema inference — when building a schema from heterogeneous fields, the union type gives the most specific annotation that fits all observed types.

Note that type any in the result means the engine found no shared structure. In practice, a result of type any means the column or value will not have useful type annotations and operations on it may be slower or require explicit type casts.

Examples

Example 1: Union of a type with its nullable variant

Type.Union({type number, type nullable number})
Result
Result
1type nullable number

Example 2: Union of incompatible types produces type any

Type.Union({type number, type text})
Result
Result
1type any

Example 3: Union of identical types returns that type unchanged

Type.Union({type text, type text})
Result
Result
1type text

Compatibility

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