Forum Discussion

Fistachpl's avatar
Fistachpl
Helper III
2 years ago
Solved

Cumulative sales

Hello I need to calculate the cumulative sales

On the page I have filters apllied and I just need to calculate the mesaure Sold CY but do it in a cumulative way.

 

First column is a month

 

 

It should be:
Jan 260
Feb 260 +339 
march 260 + 339 +260 etc.

 

 

I try to do this by:

 

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('Dane sprzedaży';'Dane sprzedaży'[Workers.SprzedażTowaru.OkresOperacji.Do].[Rok]=2024)

    )

 

RETURN _cumulativeSales

 

but it keeps calculating it for each month separately.

 

  • Anonymous's avatar
    Anonymous
    2 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.

3 Replies

  • 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~

    • Fistachpl's avatar
      Fistachpl
      Helper III

      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:

      In third row we already have a mistake: 260 + 339 +260 should be 859 instead of 851
  • Anonymous's avatar
    Anonymous
    Not applicable

    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.