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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Dunner2020
Post Prodigy
Post Prodigy

Cumulative sum of remaining months

Hi there,

 

I have a table which looks like as follow:

leo_89_0-1603150744348.png

 

 

This table is connected with a date table which has got RY Month number. April has RY month number =1 and Mar has RY month = 12. I want to calculate the cumulative sum of the value of those months who has not gone yet. It should look like as follow:

leo_89_1-1603150785241.png

 

 

So I am creating measure something like as follow:

Unplanned forecast debug =

Var _CYMonth = MONTH(TODAY())
Var _RYMonth = if(_CYMonth > 3 && _CYMonth <= 12, _CYMonth - 3,_CYMonth + 9)
 
Var remain_month = SUM('Table'[Value])

Var remain_month_cum = SUMX(FILTER(ALL('Table'),Max('Table'[Month Number])>= _RYMonth),remain_month)
Return
IF(max(Dates[RY Month Number])>= _RYMonth,remain_month_cum ,BLANK() )

 

 

However, it does not produce the desired result. Could anyone help me where am I  making the mistake?

Link of file: https://1drv.ms/u/s!AucycxZHFe9TjUOV3GfsP_bL3FcC?e=LwTupY

1 ACCEPTED SOLUTION

@Dunner2020 , you might want to try this measure to achieve desired values,

Cumulative measure = 
VAR _CYMonth = MONTH ( TODAY () )
VAR _RYMonth = IF ( _CYMonth > 3, _CYMonth - 3, _CYMonth + 9 )
RETURN
    SUMX (
        FILTER (
            ALL ( '5y average' ),
            '5y average'[Month Number] <= MAX ( '5y average'[Month Number] )
                && '5y average'[Month Number] >= _RYMonth
        ),
        CALCULATE ( SUM ( '5y average'[Value] ) )
    )

Screenshot 2020-10-20 093712.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur , I have attached dummy file in the post. Unfortunately, your calculation did not work in my file. 

Hi,

Your solution is not even remotely close to what i have suggested.  In your visual, Year and Month name have to be dragged from the Calendar Table.  Furthermore, your cumulative measure is nowhere close to mine.  Please study the file that i have shared with you, very carefully.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
CNENFRNL
Community Champion
Community Champion

Hi, @Dunner2020 , as to your measure, an error lies in the misuse of variable in this part, I think.

Var remain_month = SUM('Table'[Value])
Var remain_month_cum = SUMX(FILTER(ALL(Dates),Dates[RY Month Number]>=_RYMonth),remain_month)

In fact, variables in DAX are NOT THAT VARIABLE as expected!

In DAX, variables are calculated within the scope in which they are written, and then the result of them is stored and used in the rest of the expression.

You might want to refer to an article on this subject for more details.

Without a complete data model, it's hard to debug to the fullest extent. If you attach a dummy file with enough mockup data, it's way much easier to troubleshoot.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL I have included the dummy file in the actual post. 

@Dunner2020 , you might want to try this measure to achieve desired values,

Cumulative measure = 
VAR _CYMonth = MONTH ( TODAY () )
VAR _RYMonth = IF ( _CYMonth > 3, _CYMonth - 3, _CYMonth + 9 )
RETURN
    SUMX (
        FILTER (
            ALL ( '5y average' ),
            '5y average'[Month Number] <= MAX ( '5y average'[Month Number] )
                && '5y average'[Month Number] >= _RYMonth
        ),
        CALCULATE ( SUM ( '5y average'[Value] ) )
    )

Screenshot 2020-10-20 093712.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors