Forum Discussion
DAX - Running 365 Day Total
I expected the total for a date to be the sum of all Quantities for the previous 365 days. So for the row with 2/15/16 as TheDate I expected the sum of all quantities between 02/15/15 through 02/15/16 which would include the following:
02/15/15 - 10
03/02/15 - 10
03/15/15 - 10
01/01/16 - 1
01/15/16 - 1
02/01/16 - 1
02/15/16 - 1
For a total of 34.
Bob
- Sean10 years ago
Community Champion
When you subtract 365 days - you do end up at 2/15 again (if not a Leap Year)
However you don't include that date in your calculation.
- v-sihou-msft10 years ago
Microsoft Employee
Hi ryard,
If you also want to include same date of previous year in your calculation, you could use DATESBETWEEN() in your filter.
CYS2 = calculate(
sum(Table1[Quantity]),
DATESBETWEEN(Table1[TheDate],
FIRSTDATE(PARALLELPERIOD(Table1[TheDate],-1,YEAR)),
LASTDATE(PARALLELPERIOD(Table1[TheDate],0,YEAR)),
)
)
Reference:
DATESBETWEEN Function (DAX)Regards,