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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

IF ELSE Expression.Error: We cannot apply operator - to types Date and DateTime.

Hi,

 

I am new to Power BI. I have been having a hard time trying to replicate this formula in Power BI:

 

=IF([@[Return Approved Date]]="","NO APPROVAL DATE",ROUNDDOWN($BC$1-[@[Return Approved Date]],0)) 

where $BC$1 is TODAY()

 

I added a custom column using this formula 

 

Laedays_0-1617881333048.png

However, the value of that returns Error only.

 

Please help..

 

 

2 ACCEPTED SOLUTIONS
MFelix
Super User
Super User

Hi @Anonymous ,

Is today a column on your data model? you need to use a DATEDIFF formula that in M language is DURATION.

 

check the formulas on the link below:

https://docs.microsoft.com/en-us/powerquery-m/duration-functions

 

Also if you want to pick todays date you need to use 

DateTime.LocalNow() 

 Try the following code:

if  [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )


- [Return Approved Date]))

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

Hi @Anonymous ,

 

Using the Today column will also work the only question is that if you are using that column only for this calculation this will have an increase of data in your model, so there is no need to have this additional column on the model since you can do the calculation to make use of the today column redo the formula to:

if  [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( [Today] - [Return Approved Date]))

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

6 REPLIES 6
MFelix
Super User
Super User

Hi @Anonymous ,

Is today a column on your data model? you need to use a DATEDIFF formula that in M language is DURATION.

 

check the formulas on the link below:

https://docs.microsoft.com/en-us/powerquery-m/duration-functions

 

Also if you want to pick todays date you need to use 

DateTime.LocalNow() 

 Try the following code:

if  [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )


- [Return Approved Date]))

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix , do you mind if i ask you to help me understanding the code below:

 

Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )

 

like can you please how it works step by step?

 

thanks!

Anonymous
Not applicable

This actually worked. Thank you! Before I press the accept as solution. May i know if using Today column will work too? I have created a column for today which is 

DateTime.LocalNow() 

 

Hi @Anonymous ,

 

Using the Today column will also work the only question is that if you are using that column only for this calculation this will have an increase of data in your model, so there is no need to have this additional column on the model since you can do the calculation to make use of the today column redo the formula to:

if  [Return Approved Date] = null then "No Approved date" else Duration.Days (Duration.From( [Today] - [Return Approved Date]))

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hello @MFelix Can you also explain to me the logic behind the code below:

 

Duration.Days (Duration.From( #date(Date.Year(DateTime.LocalNow()), Date.Month(DateTime.LocalNow()), Date.Day(DateTime.LocalNow()) )

 

I just need more understanding how it works.

 

Thanks!

Anonymous
Not applicable

Thank you so much @MFelix

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.