Type.Union

Updated on

Type.Union is a Power Query M function that computes the union of the types in the input list. The function returns a new type that represents the union of the input types.

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

Syntax

Type.Union( types as list ) as type

Description

The Type.Union function returns a type value that is a combination of two types. When possible, the operation returns the same type. For instance when combining two table types, or two record types. Trying to combine type null with another type usually results in the nullable form of the type. When you combine values that can’t easily be merged, the function may return type any.

Examples

Suppose you have two record types that you want to combine. Power Query can merge those into a single record type.

// Output: type [ A = text, B = number ]
let 
  type1 = type [ A = text ], 
  type2 = type [ B = number ],
  combinedRecord = Type.Union( { type1, type2 } )
in
  combinedRecord 

When you combine different types with null, the operation will try to give you a nullable type.

// Output: type { nullable number }
let 
  type1 = type { number }, 
  type2 = type null,
  combinedRecord = Type.Union( { type1, type2 } )
in
  combinedRecord

However, there are situations where a type is not of the same sort and can’t be merged into the same type. In that case power query returns ‘type any’.

// Output: type any
let 
  type1 = type {number}, 
  type2 = type [ B = number ],
  combinedRecord = Type.Union( { type1, type2 } )
in
  combinedRecord

Other functions related to Type.Union are:

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

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy