0
votes

I have :

Quantity Sold LY = CALCULATE([Total Quantity Sold], DATEADD(Dates[Date], -1, YEAR))

and I want to calculate the quantity sold last year to date :

Quantity Sold LYTD = CALCULATE([Quanity Sold LY], DATESYTD(Dates[Date]))

BUT, when I combine these two and write it as follow, the results are totally different:

total quantity sold last 1 year =  
VAR L1Y=  CALCULATE([Total Quantity Sold], DATEADD(Dates[Date], -1, YEAR)) 
return 

CALCULATE(L1Y, DATESYTD(Dates[Date]))

can anyone explain why?

1

1 Answers

0
votes

When you create the variable L1Y, it is stored as a constant.

Suppose L1Y evaluates to be 152. Then your last calculation would be equivalent to

CALCULATE(152, DATESYTD(Dates[Date]))

I think you want to do something like this:

CALCULATE([Total Quantity Sold], DATEADD(DATESYTD(Dates[Date]), -1, YEAR))