I have the following measure to calculate case sales in the last 12 months from the selected slicer end date. I would expect it to filter sales based on the provided start and end date variables included in the filter, however when looking at the dates included in the sales graph it includes start dates well past the last 12 months. I have included cards below the graph which show the start and end date calculations.
Cases Total Current 12mo (Slicer) =
VAR EndDate =
DATE ( YEAR ( MAX( 'Date'[Date] ) ), MONTH ( MAX ( 'Date'[Date] ) ), 1 )
VAR StartDate =
EDATE ( EndDate, -11 )
RETURN
CALCULATE (
SUM ( Sales[Cases] ),
FILTER ( 'Date', 'Date'[Date] >= StartDate && 'Date'[Date] <= EndDate )
)
I am at a loss as to why the start and end dates are correct in the included cards, but those same dates are not applying to the start date of the calculation filter.
Any help would be greatly appreciated!
Based on your formula:
Cases Total Current 12mo (Slicer) =
VAR EndDate =
DATE ( YEAR ( MAX( 'Date'[Date] ) ), MONTH ( MAX ( 'Date'[Date] ) ), 1 )
VAR StartDate =
EDATE ( EndDate, -11 )
RETURN
CALCULATE (
SUM ( Sales[Cases] ),
FILTER ( 'Date', 'Date'[Date] >= StartDate && 'Date'[Date] <= EndDate )
)
The calculation is evaluated for each bar in the bar chart. For instance, for May 2023
, we can assume the following:
MAX ( 'Date'[Date] )
will evaluate to 2023-05-31
EndDate
will evaluate to the 1st date in the maximum year/month in the evaluation context
2023-05-01
StartDate
will evaluate to a date 11 months prior to EndDate
2022-06-01
SUM
over Sales[Cases]
will then aggregate rows in this time period