Forum Discussion
SUM with datefilter
- 9 years ago
Hey,
you can uses this DAX statement to create your measure
Measure = var yearToday = YEAR(TODAY()) var yearStart = yearToday - 3 var theDatesTable = DATESBETWEEN('Calendar'[Date], DATE(yearStart, 6, 30),DATE(yearToday, 6, 30)) return CALCULATE( SUM('FactWithDates'[Amount]) ,theDatesTable )Please be aware that this Measure heavily relies on the common practice to use a separate calendar/date table, where this date table relates to your fact table, please also have a look to at this site where a lot of common date related calculations are explained: daxpatterns.com/time-patterns
Hm, I'm wondering if your start should be 7/1/year(today())-3 (representing the 1st of July 3 years ago), if you want to cover complete 12 months.
Regards
Tom
Hey,
you can uses this DAX statement to create your measure
Measure =
var yearToday = YEAR(TODAY())
var yearStart = yearToday - 3
var theDatesTable = DATESBETWEEN('Calendar'[Date], DATE(yearStart, 6, 30),DATE(yearToday, 6, 30))
return
CALCULATE(
SUM('FactWithDates'[Amount])
,theDatesTable
)Please be aware that this Measure heavily relies on the common practice to use a separate calendar/date table, where this date table relates to your fact table, please also have a look to at this site where a lot of common date related calculations are explained: daxpatterns.com/time-patterns
Hm, I'm wondering if your start should be 7/1/year(today())-3 (representing the 1st of July 3 years ago), if you want to cover complete 12 months.
Regards
Tom