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
luisccmm
Helper II
Helper II

Rolling Sum with SUMX not working as row-wise

I have created a Measure that is working correctly but I am failling to create  Rolling Sum from it.

The following is the original measure. At the end, after "Return" there are 2 main parts on the multiplication expression,
Part1) there is a SUMX function that calculates a ratio for each Yearmonth and then multiplies by
Part2) sum of ([Active_contracts]+[Future_contracts])

Till here there is no problem.

 

 

Month_value_measure=
var _fin=max(Calendario_forecast[Fecha])
var _days=max(Forecast_periodo[Forecast_periodo])
var _start=max(Calendario_forecast[Fecha])-_days
var _maxyear=max('Master Calendar'[Year])
var _laborables=
CALCULATE(sum('Master Calendar'[Working_day_flag]),
FILTER(all('Master Calendar'[Fecha]),'Master Calendar'[Fecha]>=_start&&'Master Calendar'[Fecha]<=_fin))
return
SUMX (
    VALUES ( 'Master Calendar'[Year_month_num] ),
    DIVIDE (
        CALCULATE (
            DIVIDE (
                CALCULATE (
                    DIVIDE ( [Churned_contracts], [Active_Contracts] ),
                    FILTER (
                        ALL ( 'Master Calendar'[Date] ),
                        'Master Calendar'[Date] >= _start
                            && 'Master Calendar'[Date] <= _fin
                    )
                ),
                _working_days
            ) * [Working_days_acumulative],
            FILTER ( 'Master Calendar', 'Master Calendar'[Date] >= _fin )* ([Active_contracts]+[Future_contracts])

 

 

Results
Results from above measure  are used with Master Calendar Yearmonth colum, producing one value for each month as follows.

Year_month_numMonth_value_measure 
202310120 
202311200 
202312300 


What I am looking for?  Calculating Rolling SUM for each value of Month_value_measure (remember that results are aggregated by Yearmonth_num), producing something like the third column from the following table.

 

Year_month_numMonth_value_measureRolling_sum_measure
202310120120
202311200320
202312300620

 

My Attempt Problem.

THe problem  comes when I try to calculate a Rolling SUM from this last measure, as I need to calculate it  row-wise and then sum the total from each row. What it is actually doing (not expected ) is summing all values from Part1) and multiply them by the sum of all values from Part2)

The following is not working

 

 

Rolling_sum_measure=
var _fin=max(Calendario_forecast[Fecha])
var _days=max(Forecast_periodo[Forecast_periodo])
var _start=max(Calendario_forecast[Fecha])-_days
var _maxyear=max('Master Calendar'[Year])
var _laborables=
CALCULATE(sum('Master Calendar'[Working_day_flag]),
FILTER(all('Master Calendar'[Fecha]),'Master Calendar'[Fecha]>=_start&&'Master Calendar'[Fecha]<=_fin))
return
SUMX (
    VALUES ( 'Master Calendar'[Year_month_num] ),
    DIVIDE (
        CALCULATE (
            DIVIDE (
                CALCULATE (
                    DIVIDE ( [Churned_contracts], [Active_Contracts] ),
                    FILTER (
                        ALL ( 'Master Calendar'[Date] ),
                        'Master Calendar'[Date] >= _start
                            && 'Master Calendar'[Date] <= _fin
                    )
                ),
                _working_days
            ) * [Working_days_acumulative],
            FILTER ( 'Master Calendar', 'Master Calendar'[Date] >= _fin )* ([Active_contracts]+[Future_contracts]),
    FILTER (
        ALL ( 'Master Calendar'[Date] ),
        'Master Calendar'[Date] <= MAX ( 'Master Calendar'[Date] )
    ),
    'Master Calendar'[Year] = _maxyear
)

 

 


¿How I can make the last measure to sum value from the first one in a  row-wise style as a rolling sum function?

2 REPLIES 2
Abhinav054
Helper I
Helper I

Hii, once use the following DAX measure

RollingSum =        VAR _fin=max(Calendario_forecast[Fecha])
                              VAR _days=max(Forecast_periodo[Forecast_periodo])
                               VAR _start=max(Calendario_forecast[Fecha])-_days
                               VAR _maxyear=max('Master Calendar'[Year])
                               VAR _laborables=
                                CALCULATE(sum('Master Calendar'[Working_day_flag]),
                                FILTER(all('Master Calendar'[Fecha]),'Master Calendar'[Fecha]>=_start&&'Master                                                                          Calendar'[Fecha]<=_fin))
                                VAR _originalMeasure =
                                SUMX (
                                             VALUES ( 'Master Calendar'[Year_month_num] ),
                                 DIVIDE (
                                        CALCULATE (
                                                  DIVIDE (
                                                          CALCULATE (
                                                                      DIVIDE ( [Churned_contracts], [Active_Contracts] ),
                                                                               FILTER (
                                                                                          ALL ( 'Master Calendar'[Date] ),
                                                                                          'Master Calendar'[Date] >= _start
                                                                                            && 'Master Calendar'[Date] <= _fin
                                                                        )
                                                                ),
                                 _working_days) * [Working_days_acumulative],
                                                            FILTER ( 'Master Calendar', 'Master Calendar'[Date] >= _fin )*                                                                                                  ([Active_contracts]+[Future_contracts])
                                                        )
                                                 )

                                      RETURN
                                                  SUMX (
                                                                ALL ( 'Master Calendar'[Date] ),
                                                                                CALCULATE (
                                                                                         _originalMeasure,
                                                                                         FILTER (
                                                                                                 ALL ( 'Master Calendar'[Date] ),
                                                                                                         'Master Calendar'[Date] <= CURRENTROW()
                                        )
                     )
)

Hi @Abhinav054 ,

Thanks for your answer but it is not working as expected, some reasons might be (not sure).
1) I See on your proposal a function that is not DAX language   CURRENTROW()
2) On mi original formula the values are agregated in SUMX function by Yearmonth, whereas in your proposal you are using Date column

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.