Forum Discussion
Running Total for different products and stores
- Sep 10, 2023
Not sure what is desired output. With
slsRT:=CALCULATE ( SUM ( 'Sales'[SLS] ), FILTER ( ALLEXCEPT ( 'Sales', 'Sales'[Product], Sales[Store] ), 'Sales'[YEARWEEK] <= MAX ( 'Sales'[YEARWEEK] ) ) )it's like
SergeiBaklan That's great thank you!
There is one (hopefully) last complication: my real database includes many more columns that are product attributes (i.e. material, color) which I may use as filters when working with the Pivot, is there a way to take this into account in your formula without having to add all the columns into the ALLEXCEPT section?
Sorry for some delay. You may use
filterRT :=
VAR maxW =
MAX ( Sales[YEARWEEK] )
RETURN
CALCULATE (
SUM ( 'Sales'[SLS] ),
VALUES ( 'Sales'[Product] ),
'Sales'[YEARWEEK] <= maxW
)
For the sample
I added STOCK filtering into previous measure
slsRT :=
CALCULATE (
SUM ( 'Sales'[SLS] ),
FILTER (
ALLEXCEPT ( 'Sales', 'Sales'[Product], Sales[Store], Sales[STOCK] ),
'Sales'[YEARWEEK] <= MAX ( 'Sales'[YEARWEEK] )
)
)
both give the same result.
- stevebortyOct 23, 2023Copper Contributor
Hi SergeiBaklan!
Sorry for my very late reply. I've been using your slsRT method and it works perfectly. Yet, my database contains many additional attributes that I may eventually need as filters. Is there a way to change the red code
slsRT :=
CALCULATE (
SUM ( 'Sales'[SLS] ),
FILTER (
ALLEXCEPT ( 'Sales', 'Sales'[Product], Sales[Store], Sales[STOCK] ),
'Sales'[YEARWEEK] <= MAX ( 'Sales'[YEARWEEK] )
)
)in order to state something like "all the columns except the YEARWEEK". I tried to use two nested ALLEXCEPT, but it does not work.
Many thanks!
- SergeiBaklanOct 23, 2023Diamond Contributor
Did you try filterRT instead?
- stevebortyNov 10, 2023Copper Contributor
SergeiBaklan I did, but it seems to be resetting when the new year begins if I use a broader set of data, while I'd like the running total to take into account the whole period.
You can find attached a test, as you can see I may need to see the running totals grouped by store or directly using the product model instead of the product code, that's why in the slsRT formula I would have to insert all the necessary columns.
Thanks a lot!