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
bchager6
Super User
Super User

[Expression.Error] We cannot convert the value null to type Logical.

Hi All...

 

I've read through a few similar threads but didn't find a solution to my problem. Hoping someone can assist.

I'm using the following code in Power Query to assign a fiscal year (FY) to a row when certain date conditions are met within the startdate and enddate columns for a project.

each if[startdate] <> null or [enddate] <> null and [active] = "1" and [live] = "1" and [latest] = "Green" and [startdate] > #date(2020,3,31) and [enddate] < #date(2021,4,1) then "FY21" else ""

I would like to exclude rows from the expression when the startdate or enddate is null.

I receive the following error with the code I wrote when there is a null value in either the startdate or enddate column: [Expression.Error] We cannot convert the value null to type Logical.

Kudos to anyone who can help!


1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

null values can trip you up when used in if statements, and also with equality operators. I would try:

 

each if [startdate] = null then "" else if [enddate] = null then "" else if [active] = "1" and [live] = "1" and [latest] = "Green" and [startdate] > #date(2020,3,31) and [enddate] < #date(2021,4,1) then "FY21" else ""

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

4 REPLIES 4
bchager6
Super User
Super User

Thanks, guys. What works best for my use case is to replace the null values with "".

watkinnc
Super User
Super User

But if you are actually trying to exclude the rows, you should just select the rows:

 

Table.SelectRows(PriorStepName, each not is null ([startdate]) and not is null ([enddate]) and [active] = "1" and [live] = "1" and [latest] = "Green" and [startdate] > #date(2020,3,31) and [enddate] < #date(2021,4,1))

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

null values can trip you up when used in if statements, and also with equality operators. I would try:

 

each if [startdate] = null then "" else if [enddate] = null then "" else if [active] = "1" and [live] = "1" and [latest] = "Green" and [startdate] > #date(2020,3,31) and [enddate] < #date(2021,4,1) then "FY21" else ""

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
AlexisOlson
Super User
Super User

I think it may be trying to compute the "null and [active]" part. You can probably resolve this by adding parentheses to clarify the order of operations.

 

At minimum, add these ones:

each if ( [startdate] <> null or [enddate] <> null ) and [active] = "1" and [live] = "1" and [latest] = "Green" and [startdate] > #date(2020,3,31) and [enddate] < #date(2021,4,1) then "FY21" else ""

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