0
votes

I'm new in dax and trying to create a calculated column in a calendar table for which I want values to be returned in a new column 1 or 0 based if the CalendarDate is in the period. I tried the following which returns the correct values but I need to change after "&&" that it returns the dates - 2 month from last sales date.

"Last 2 periods"; If ([Date]<=LASTDATE(Sales[SalesDate]) 
&& [Date]> DATE(2019;10;02);1;0);

I tried following but this does not work:

"Last 2 periods"; If ([Date]<=LASTDATE(Sales[SalesDate]) 
&& [Date]> DATEADD(LASTDATE(Sales[SalesDate]);-2;MONTH);1;0);

Any suggestions? Or proposals for the best way to create this column in DAX?

1

1 Answers

0
votes

You should be using the max function instead of last date. The sample calculation would look like below:

Last 2 Periods = IF(Sales[Date]<=MAX(Sales[SalesDate])&&DATEADD(Sales[Date].[Date],2,MONTH)>max(Sales[SalesDate]),1,0)