Forum Discussion
Add days to date in PowerQuery
if Date.AddDays([Date_example],-30) < #date(2024,7,1)
then Date.AddDays([Date_example],-44)
else Date.AddDays([Date_example],-29)
- Anonymous2 years ago
Hi Anonymous
According to the error message, the error occurs because the data on both sides of "<" sign are of different types. From the screenshot, it seems you don't change the data type with Power Query, so I guess that you may have changed the date column to date format in Excel, however its values are probably still in datetime type, which may cause this error. For example,
To resolve this error, you can add a step to change the date column to date type in Power Query Editor before adding the custom column.
In addition, when you add this custom column, modify the last ELSE result to null instead of "".
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!
5 Replies
- HotChilliCommunity Champion
What's the full error message?
- tackytechtomMost Valuable Professional
Hi Anonymous ,
I tried your code with an example in Power BIs Power Query and it worked out well:
Could it be that your Date_example column is of the wrong data type (not a date column)?
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/- AnonymousNot applicable
I checked and my Date_Example column is of the type "Date". I found another error regarding null values but have fixed that and am now back to the operator error. Here is my current code and the error message I am getting.
- AnonymousNot applicable
Hi Anonymous
According to the error message, the error occurs because the data on both sides of "<" sign are of different types. From the screenshot, it seems you don't change the data type with Power Query, so I guess that you may have changed the date column to date format in Excel, however its values are probably still in datetime type, which may cause this error. For example,
To resolve this error, you can add a step to change the date column to date type in Power Query Editor before adding the custom column.
In addition, when you add this custom column, modify the last ELSE result to null instead of "".
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!