Type.Union

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, in situations where a type is not of the same sort and can’t be merged into the same type.

// 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:

BI Gorilla Youtube Channel

Last update: August 17, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/type-union
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.