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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Brotedo
Helper I
Helper I

Rolling Sum that Uses a Variable Factor

I have a monthly sales dataset, like this:

MonthIndexSales
145
255
345
440
550
640
770
860
950

10

55
1150
1240

And I have a table of factors, like this:

MonthsFromCurrentFactor
0.7
1.5
2.2
3.06

I need a measure that, for the given month, calculates the sum of the products of the sales and factors. For example, if the current month is 6, I want the measure to output (40*.7 + 70*.5 + 60*.2 + 50*.06) = 78 

The factor for all other months is 0.

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @Brotedo ,

 

Maybe you can try this.

Measure =
VAR _currentmonth =
    SELECTEDVALUE ( Parameter[Parameter] )
VAR _f =
    ADDCOLUMNS (
        'factors',
        "sales1",
            CALCULATE (
                SUM ( sales[Sales] ),
                FILTER (
                    'sales',
                    [MonthIndex]
                        = EARLIER ( [MonthsFromCurrent] ) + _currentmonth
                )
            ) * [Factor]
    )
RETURN
    SUMX ( _f, [sales1] )

 

Result:

vchenwuzmsft_0-1661934895220.gif

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @Brotedo ,

 

Maybe you can try this.

Measure =
VAR _currentmonth =
    SELECTEDVALUE ( Parameter[Parameter] )
VAR _f =
    ADDCOLUMNS (
        'factors',
        "sales1",
            CALCULATE (
                SUM ( sales[Sales] ),
                FILTER (
                    'sales',
                    [MonthIndex]
                        = EARLIER ( [MonthsFromCurrent] ) + _currentmonth
                )
            ) * [Factor]
    )
RETURN
    SUMX ( _f, [sales1] )

 

Result:

vchenwuzmsft_0-1661934895220.gif

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

tamerj1
Super User
Super User

Hi @Brotedo 

please try

NewMeasure =
SUMX (
    FILTER (
        ALLSELECTED ( Sales ),
        Sales[MonthIndex] >= MAX ( Sales[MonthIndex] )
            && Sales[MonthIndex]
                < MAX ( Sales[MonthIndex] ) + COUNTROWS ( Factors )
    ),
    SUMX (
        FILTER ( Factors, Factors[MonthsFromCurrent] = Sales[MonthIndex] ),
        Sales[Sales] * Factors[Factor]
    )
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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