Type.Is
TypeChecks whether a type is compatible with (a subtype of) another type.
Syntax
Type.Is(type1 as type, type2 as type) as logicalParameters
| Name | Type | Required | Description |
|---|---|---|---|
type1 | type | Yes | The type to check. |
type2 | type | Yes | The base type to check compatibility against. |
Return Value
logical — true 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 | |
|---|---|---|
| 1 | number vs number | TRUE |
| 2 | text vs any | TRUE |
| 3 | text vs number | FALSE |
| 4 | record vs any | TRUE |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks