Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
FelipMark
Helper I
Helper I

Conditional column with null value error

Hey guys, i created a conditional column of a date field, but when the field is "null" the conditional column returns error. Can you tell the reason?

 

= Table.AddColumn(#"Colunas Removidas1", "Status",
each if [DTENTREGA] < [DTPREVENT] then "Early"
else if [DTENTREGA] > [DTPREVENT] then "Late"
else if [DTENTREGA] = [DTPREVENT] then "On Time"
else if [DTENTREGA] = null then "In Progress"
else "Dispatch")

FelipMark_0-1679929226268.png

Error: Expression.Error: We are unable to convert null value to Logical type. Details: Value= Type=[Type]

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hello - you have to either filter out the nulls first, or use try-otherwise to step over them.

 

Filter out the nulls first would be like this:

= Table.AddColumn(#"Colunas Removidas1", "Status",
each if [DTENTREGA] = null or [DTPREVENT] = null then null
else if [DTENTREGA] < [DTPREVENT] then "Early"
else if [DTENTREGA] > [DTPREVENT] then "Late"
else if [DTENTREGA] = [DTPREVENT] then "On Time"
else if [DTENTREGA] = null then "In Progress"
else "Dispatch")

Using try-otherwise would be like this, but it is riskier since there could be other errors that are overstepped. 

= Table.AddColumn(#"Colunas Removidas1", "Status",
each try 
if [DTENTREGA] < [DTPREVENT] then "Early"
else if [DTENTREGA] > [DTPREVENT] then "Late"
else if [DTENTREGA] = [DTPREVENT] then "On Time"
else if [DTENTREGA] = null then "In Progress"
else "Dispatch" otherwise null)

 

 

View solution in original post

3 REPLIES 3
jennratten
Super User
Super User

Hello - you have to either filter out the nulls first, or use try-otherwise to step over them.

 

Filter out the nulls first would be like this:

= Table.AddColumn(#"Colunas Removidas1", "Status",
each if [DTENTREGA] = null or [DTPREVENT] = null then null
else if [DTENTREGA] < [DTPREVENT] then "Early"
else if [DTENTREGA] > [DTPREVENT] then "Late"
else if [DTENTREGA] = [DTPREVENT] then "On Time"
else if [DTENTREGA] = null then "In Progress"
else "Dispatch")

Using try-otherwise would be like this, but it is riskier since there could be other errors that are overstepped. 

= Table.AddColumn(#"Colunas Removidas1", "Status",
each try 
if [DTENTREGA] < [DTPREVENT] then "Early"
else if [DTENTREGA] > [DTPREVENT] then "Late"
else if [DTENTREGA] = [DTPREVENT] then "On Time"
else if [DTENTREGA] = null then "In Progress"
else "Dispatch" otherwise null)

 

 

it worked, thanks for the help!!

You're welcome!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors