Forum Discussion
Power Query Date.AddMonths not working
- 5 years ago
Hi Anonymous
That fx button is to invoke a custom function that you've already written, not to call inbuilt functions.
To deduct 6 months from your date column just click the Custom Column button
and add this in the code box
Regards
Phil
Anonymous , The syntax seems correct for power query
Date.AddMonths([Date],-6) //if Date is date data type
https://www.youtube.com/watch?v=S_meG32rDio
in case datetime try
Date.AddMonths(DateTime.Date([Date]),-6)
But not all functions work in Direct Query. But that should give import mode warning option
- Anonymous5 years agoNot applicable
Hi amitchandak Thank you for your fast response. It was a DateTime field. But I still get the same error.
Do I need to define the field shorthand somewhere before it works?
- amitchandak5 years agoSuper User
Anonymous , I tried on Direct Query
Date.AddMonths(DateTime.Date([Date]),-1) is not supported in Direct Query
But I was able to do Date.AddMonths([Sales Date],-1) //but my date to not have time
- Anonymous5 years agoNot applicable
Hi amitchandak Thank you for your help. I don't think it will work in directquery. I've made a new date table to which I could add it.