Type.Is

Type

Checks whether a type is compatible with (a subtype of) another type.

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

Syntax

Type.Is(type1 as type, type2 as type) as logical

Parameters

NameTypeRequiredDescription
type1typeYesThe type to check.
type2typeYesThe base type to check compatibility against.

Return Value

logicaltrue if type1 is compatible with type2; false otherwise.

Remarks

Type.Is determines whether type1 is compatible with (i.e., a subtype of or equal to) type2. This is the M equivalent of an "is-a" type check.

For example, Type.Is(type number, type number) returns true, and Type.Is(type text, type any) also returns true because all types are subtypes of any.

This function is useful in generic or meta-programming scenarios where you need to branch logic based on the type of a column or value.

Examples

Example 1: Check type compatibility

let
    Checks = {
        {"number vs number", Type.Is(type number, type number)},
        {"text vs any", Type.Is(type text, type any)},
        {"text vs number", Type.Is(type text, type number)},
        {"record vs any", Type.Is(type record, type any)}
    }
in
    #table({"Check", "Result"}, Checks)
Result
Check
Result
1number vs numberTRUE
2text vs anyTRUE
3text vs numberFALSE
4record vs anyTRUE

Compatibility

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