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
Type.IsNullable( type as type ) as logical
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
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.
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
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
any type, a more encompassing data type, inherently supports null values without requiring the
// 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: