Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
let
Source = {
[ID = 1, Name = "Alice", Age = 30, IsActive = true, Address = [Street = "123 Main St", City = "Metropolis", ZipCode = 12345]],
[ID = 2, Name = "Bob", Age = 35, IsActive = false, Address = null], // Address is null here to demonstrate nullable complex fields
[ID = 3, Name = "Charlie", Age = 25, IsActive = true, Address = [Street = "456 Elm St", City = "Gotham", ZipCode = 67890]]
},
ConvertedToTable = Table.FromRecords(Source),
Address = type [
Street = text,
City = text,
ZipCode = Int64.Type
],
Schema = type table [
ID = Int64.Type,
Name = text,
Age = Int64.Type,
IsActive = logical,
Address = nullable Address
],
ChangedType = Table.ChangeType(ConvertedToTable, Schema)
in
ChangedType{1}[Address]
Solved! Go to Solution.
Thanks for the reply! If anyone else comes accross this issue, I ended up modifing the function from https://learn.microsoft.com/en-us/power-query/helper-functions#tablechangetype to accept nulls
...
Record.ChangeType = (record as nullable record, recordType as type) =>
if record = null then record else
...
Same idea for list
Thanks for the reply! If anyone else comes accross this issue, I ended up modifing the function from https://learn.microsoft.com/en-us/power-query/helper-functions#tablechangetype to accept nulls
...
Record.ChangeType = (record as nullable record, recordType as type) =>
if record = null then record else
...
Same idea for list
Hi @DougTheDev ,
To resolve this issue, you can use the Table.TransformColumnTypes function in combination with a conditional check to ensure that null values are properly handled.
Please try this M function:
let
Source = {
[ID = 1, Name = "Alice", Age = 30, IsActive = true, Address = [Street = "123 Main St", City = "Metropolis", ZipCode = 12345]],
[ID = 2, Name = "Bob", Age = 35, IsActive = false, Address = null], // Address is null here to demonstrate nullable complex fields
[ID = 3, Name = "Charlie", Age = 25, IsActive = true, Address = [Street = "456 Elm St", City = "Gotham", ZipCode = 67890]]
},
ConvertedToTable = Table.FromRecords(Source),
// Use a custom function to handle nullable complex types
HandleNullableComplexType = (table as table, columnName as text, complexType as type) as table =>
Table.TransformColumns(table, {
columnName, each if _ is null then null else _ as complexType
}),
// Apply the custom function to the Address column
HandledNullableAddress = HandleNullableComplexType(ConvertedToTable, "Address", type nullable record),
// Define the schema
Schema = type table [
ID = Int64.Type,
Name = text,
Age = Int64.Type,
IsActive = logical,
Address = nullable type [Street = text, City = text, ZipCode = Int64.Type]
],
// Change the type according to the schema
ChangedType = Table.ChangeType(HandledNullableAddress, Schema)
in
ChangedType
In this solution, we introduce a custom function HandleNullableComplexType that explicitly checks if the value of the specified column is null before attempting to cast it to the complex type. This ensures that null values are preserved as-is without causing errors during the type conversion process.
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
14 | |
13 | |
12 | |
12 | |
12 |