Forum Discussion

Jon789's avatar
Jon789
New Member
2 years ago
Solved

Cumulative sales

Hi 

 

Relatively new Power BI user.

 

I have some monthly sales data. For example:

Year Month  £

2023 Nov  100

2023 Dec  150

2024 Jan  500

2024  Feb 350

2024  Mar  175

2024  Apr  400

 

I would like to create a line chart with cumulative sales (YTD) sales. So for 2024 - Jan YTD 500, Feb YTD 850, MAr YTD 1025, Apr YTD 1425.

 

Any advice on how I can do this would be appreciated.

 

Thank you

  • Hi Jon789 ,

    You can create YTD calculation using standard dax time intelligence functions, and one of them is TotalYTD as shown below:

    In order to take advantage of the time intelligence functions, you need to create a separate calendar table and create a relationship between your fact table and the calendar dimension table as show below:

    I attach an example pbix file.  

     

     

  • Hi Jon789,

    Please check this formula for a YTD total:

    CALCULATE(
        SUM([Sales column]),

        WINDOW(

            1, ABS,

            0, REL,

            ORDER BY(
                [Year], ASC,

                [Month], ASC

            ),

            PARTITION BY([Year])
        )

    )

     

    For more details and examples please see this video: https://youtu.be/bxSWQNSQ8rQ?si=nsynUJ7erjFdXAXt&t=2058

3 Replies

  • Hi Jon789 ,

    You can create YTD calculation using standard dax time intelligence functions, and one of them is TotalYTD as shown below:

    In order to take advantage of the time intelligence functions, you need to create a separate calendar table and create a relationship between your fact table and the calendar dimension table as show below:

    I attach an example pbix file.  

     

     

  • wini_R's avatar
    wini_R
    Solution Supplier

    Hi Jon789,

    Please check this formula for a YTD total:

    CALCULATE(
        SUM([Sales column]),

        WINDOW(

            1, ABS,

            0, REL,

            ORDER BY(
                [Year], ASC,

                [Month], ASC

            ),

            PARTITION BY([Year])
        )

    )

     

    For more details and examples please see this video: https://youtu.be/bxSWQNSQ8rQ?si=nsynUJ7erjFdXAXt&t=2058

  • Anonymous's avatar
    Anonymous
    Not applicable

    Your solutions is great DataNinja777 and wini_R 
    Hi, Jon789 

    Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

     

    How to Get Your Question Answered Quickly

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

    Best Regards

    Jianpeng Li