Type.IsNullable

Updated on

Type.IsNullable is a Power Query M function that determines if a given type is nullable. The function returns true if the type is nullable and false otherwise.

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

Syntax

Type.IsNullable( type as type ) as logical

Description

The Type.IsNullable function is designed to determine whether a specified data type is nullable, meaning it can accept null values.

It takes a single input: the data type to be assessed, which can range from primitive types like text or number to more complex types. The function evaluates whether the provided type inherently allows for null values or has been explicitly declared as nullable using the nullable keyword. It returns a boolean value, true if the type is nullable and false if not.

Examples

Let’s look at a few examples to illustrate how this function works with various data types.

Determining Nullable Status of Text Type

You can use the following expression to test whether the type text is nullable.

// Output: false
Type.IsNullable( type text )

This demonstrates that the standard text type cannot accommodate null values, but only supports text.

Transforming Primitive Types to Support Null Values

Any primitive type can, however, transform into a form that supports null values by using the ‘nullable’ keyword. Here’s how:

// Output: true
Type.IsNullable( type nullable text )

This example shows how the ‘nullable’ keyword extends the flexibility of the text type.

Applying Nullable to the Type Anynonnull

Even a type like anynonnull, which by definition excludes null values, can be made nullable:

// Output: true
Type.IsNullable( type nullable anynonnull)

This shows the flexibility of the ‘nullable’ keyword in altering data type properties.

Nullable Nature of the Type Any

The any type, a more encompassing data type, inherently supports null values without requiring the nullable keyword:

// Output: true
Type.IsNullable( type any )

In fact, the any type supports any values, so that includes nulls.

Other functions related to Type.IsNullable are:

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

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