I have a table with columns Date, Type, and Qty.
Every time I see the type 'Start', I want to spread that quantity over the next 5 days (including the Start day). Note, the Start day may not always be the 6th day as in the example.
I have a table with columns Date, Type, and Qty.
Every time I see the type 'Start', I want to spread that quantity over the next 5 days (including the Start day). Note, the Start day may not always be the 6th day as in the example.
I'd go for three measures something like this (syntax may be a little off as I'm writing without a platform to test on).
The first adds the normal records only.
SumNormal := CALCULATE(SUM(Qty),mytable[Type] = "Normal"
The second looks for the starts in the last 5 days and then divides by five.
SumStart :=
VAR CurrentDate = mytable[Date]
VAR StartDate = DATEADD([CurrentDate],-4,day)
CALCULATE(SUM(Qty)
,mytable[Type] = "Normal"
,FILTER(mytable,[Date]>= StartDate && [Date] <= CurrentDate)
)/5
Finally Add the two:
SumQty := [SumNormal] + [SumStart]
The above covers the basics but is relatively simple, it will only really work running at day level. Handling a total where some but not all of the five days the start value is spread over gets a lot more complicated.