Forum Discussion
IF ELSE Expression.Error: We cannot apply operator - to types Date and DateTime.
- 5 years ago
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])) - 5 years ago
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]))
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]))
- Anonymous5 years agoNot applicable
Thank you so much MFelix
- Anonymous5 years agoNot 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!