Forum Discussion
Nesting PREVIOUSMONTH()
I tried this, and it works, which surprises me.
Say if one wants 2 months ago, is there a reason not to just nest PREVIOUSMONTH(), i.e.
calculate([Expense],PREVIOUSMONTH(PREVIOUSMONTH('Date'[Date])))
I can write my own DAX to get 2 months ago (with out without filter context) - but on a lark, tried just nesting - and it seems to work. Any downsides?
I did try testing it a bit and there was a small but observable slowdown in the cases I looked at.
5 Replies
- jdbuchanan71Super User
I'm not sure but it might be more work for the Vertipaq engine because it is having to apply the date shift twice. The query would be
Get the list of datesShift it back 1 month
Shift if back 1 month
If you nested it 12 times would it have to apply the date shift to the list 12 times?
- AlexisOlsonSuper User
Yeah, there's a pretty good chance nesting results in a less optimal query plan compared to, say, using DATEADD.
- v-janeyg-msftCommunity Support
Hi, mmace1
You can try:
measure = CALCULATE ( [Expense], DATEADD ( 'Date'[Date], -2, MONTH ) )Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,Community Support Team _ Janey
- mmace1Impactful Individual
Thanks. And sorry, I know how to write it myself. I was more curious about the implications of nesting PREVIOUSMONTH. Seems like people think...but aren't certain, that there's 1 con - performance implications.
- AlexisOlsonSuper User
I did try testing it a bit and there was a small but observable slowdown in the cases I looked at.