Forum Discussion
Cumulative sales
- Anonymous2 years ago
Hi, Fistachpl
I create a sample table:
First, create a new column to show month number:
MonthNumber = MONTH('Table'[Date])Then create a new measure and try to use the following dax:
Cumulative Sales = CALCULATE( SUM('Table'[Sales]), FILTER( ALLSELECTED('Table'), 'Table'[MonthNumber] <= MAX('Table'[MonthNumber]) ) )Put this measure in table visual, here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Fistachpl
I don't know your model and context, but you can try below measure.
Cumulative sale =
VAR _aktualnyMiesiac = SELECTEDVALUE('TMiesiące'[Nr miesiąca]) //Current month
VAR _cumulativeSales =
CALCULATE(
SUMX('Dane sprzedaży';'Dane sprzedaży'[Workers.SprzedażTowaru.Rozchód.Ilość]); // Here sum of Sold items
FILTER(ALL('TMiesiące'[Nr miesiąca]);'TMiesiące'[Nr miesiąca]<=_aktualnyMiesiac);
FILTER(ALL('Dane sprzedaży');'Dane sprzedaży'[Workers.SprzedażTowaru.OkresOperacji.Do].[Rok]=2024);
ALL('TMiesiące')
)
RETURN _cumulativeSales
Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !
Thank you~
Just one thing. When I do:
ALL('Dane sprzedaży')
it calculates the data for more that is selected in fragmentators. Should I Keepfilters()?
Because I have fragmentators for 'Dane sprzedaży'[Kategoria], 'Dane sprzedaży'[Subkategoria] and then it counts ok. But I also have a fragmentator for the Products and if I select one it stops working.
If I add:
VAR _cumulativeSales =
CALCULATE(
SUMX('Dane sprzedaży';'Dane sprzedaży'[Workers.SprzedażTowaru.Rozchód.Ilość]);
FILTER(ALL('TMiesiące'[Nr miesiąca]);'TMiesiące'[Nr miesiąca]<=_aktualnyMiesiac);
FILTER(ALL('Dane sprzedaży');'Dane sprzedaży'[Workers.SprzedażTowaru.OkresOperacji.Do].[Rok]=YEAR(now()));
FILTER(ALL('Dane sprzedaży');'Dane sprzedaży'[Nazwa] IN VALUES('Dane sprzedaży'[Nazwa]));
)
it works - I just added filter to calculate only for selected Products (Dane sprzedaży [ Nazwa]) but it doesn't work good, at least not always. Is it good way to filter by all selected products?
wrong calculations: