Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Danimonti91
Frequent Visitor

Cumulative Sum filtered by Year

Good morning guys,

 

I am struggling with a DAX. I am trying to build a line chart that should contain 5 lines for 5 different years (From 2017 to 2022) and one line that should be the Average of previous 5 years excluding 2022. What I am trying to do is to have a cumulative sum for every year so that I will have 5 different dax already filtered by year and in the X axis I can put months or quarters.

I am using this code for the cumulative sum : 

 

1_CumulativeAmount_2021_test = CALCULATE(
                SUM('RE_Investment'[1_Amount_Adjusted]),
                FILTER(
                        ALLSELECTED('RE_Investment'),
                        'RE_Investment'[Date]<=MAX('RE_Investment'[Date]) && 'RE_Investment'[Year] =MAX('RE_Investment'[Year])
                        ))
 
Inside this dax I would like to add a filter in order to have only one year but I tried some different approach without results. 
 
Do you have an idea about how to do it?
Thanks a lot!
1 ACCEPTED SOLUTION

Hi, @Danimonti91 

 

You can try the following methods.

Column:

Year = YEAR([Date])
Month = MONTH([Date])
Cumulative sum =
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        'Table',
        [Year] = EARLIER ( 'Table'[Year] )
            && [Month] <= EARLIER ( 'Table'[Month] )
    )
)
Average =
CALCULATE (
    AVERAGE ( 'Table'[Sales] ),
    FILTER ( 'Table', [Year] = EARLIER ( 'Table'[Year] ) )
)

Result:

vzhangti_0-1667899789934.png

vzhangti_1-1667899811273.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Danimonti91 

 

Can you simplify your data and provide some sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures. I look forward to your response.

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the reply, imagine to have a table similar to the one below (I just put dummy data for an example). From this table I want to have a line chart, showing Sales for every year (Cumulative) and on the X axis I want the months or quarters. Additionally I also want the average of last years. So the chart in this case needs to have 2019 Cumulative, 2020 Cumulative, 2021 Cumulative, 2022 Cumulative and AVG from 2019 to 2021 with Months or Quarters on the X axis. 

 

Thanks a lot in advance

DateSales
1/1/201915
10/2/20197
22/3/201998
29/10/201914
1/1/20201
7/4/202034
8/10/202057
18/12/20202
3/2/202135
8/4/202123
10/8/202145
29/11/202167
7/2/202221
11/7/202245
18/10/202222
29/10/202298

Hi, @Danimonti91 

 

You can try the following methods.

Column:

Year = YEAR([Date])
Month = MONTH([Date])
Cumulative sum =
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        'Table',
        [Year] = EARLIER ( 'Table'[Year] )
            && [Month] <= EARLIER ( 'Table'[Month] )
    )
)
Average =
CALCULATE (
    AVERAGE ( 'Table'[Sales] ),
    FILTER ( 'Table', [Year] = EARLIER ( 'Table'[Year] ) )
)

Result:

vzhangti_0-1667899789934.png

vzhangti_1-1667899811273.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Danimonti91 , you can try YTD with date table, Date in visual should also come from date table

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.