Forum Discussion
MarieAmell
3 years agoFrequent Visitor
Running total compare to same date last year
Hi, I have a dataset just as below : ART_Id Date Stock Qty _Stock Last Day Stock <> 0 Nb of days 1 30/04/2020 3000 3000 1 24/06/2020 -5 2995 1 16/09/2020 -1 ...
- 3 years ago
Hi MarieAmell ,
This is my test table:
Please try following DAX to crete new columns:
Stock = CALCULATE ( SUM ( 'Table'[Stock Qty] ), FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) ) ) Last Day Stock <> 0 = IF ( 'Table'[Stock] = 0, CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Date] < EARLIER ( 'Table'[Date] ) ) ) ) Nb of days = DATEDIFF ( 'Table'[Last Day Stock <> 0], 'Table'[Date], DAY )You will get the table like this:
The result you want:
Best regards,
Yadong Fang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
3 years agoMarieAmell , try like
_Stock =
var _max1= MAX('Time'[Date])
var _max = date(year(_max1) -1, month(_max1), Day(_max1))
return
CALCULATE(
SUM(Inventory[Stock Qty])
, FILTER(ALL('Time'[Date]),
'Time'[Date]<=_max
)
)