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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
alfredorhz
Helper I
Helper I

rolling 3 values sum

Hi Cummunity
Could please help me with rolling 3 values whitout dates, for example

alfredorhz_0-1660758849337.png
Operation = value1/value2

alfredorhz_1-1660758991527.png

alfredorhz_2-1660759110551.png

Thanks a lot

 

 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @alfredorhz 
Please refer to attached file

1.png

3rolling = 
VAR CurrentIndex = Data[Index]
VAR OnAndBeforeTable = FILTER ( Data, Data[Index] <= CurrentIndex )
VAR Last3Table = TOPN ( 3, OnAndBeforeTable, [Index] )
RETURN
    IF ( 
        COUNTROWS ( Last3Table ) = 3,
        DIVIDE ( 
            SUMX ( Last3Table, [value1] ),
            SUMX ( Last3Table, [value2] )
        )
    )

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=if(CALCULATE(countrows(Data),FILTER(Data,Data[Index]>=EARLIER(Data[Index])-2&&Data[Index]<=EARLIER(Data[Index])))<=2,BLANK(),divide(CALCULATE(SUM(Data[value]),FILTER(Data,Data[Index]>=EARLIER(Data[Index])-2&&Data[Index]<=EARLIER(Data[Index]))),CALCULATE(SUM(Data[value2]),FILTER(Data,Data[Index]>=EARLIER(Data[Index])-2&&Data[Index]<=EARLIER(Data[Index])))))

Hope this helps.

Untitled.png


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

Thank yoy @Ashish_Mathur
I don´t know why the index values in the EARLY function send this error, 'parameter is not the correct type'. any clue?

 


Hi,

In the Query Editor, ensure that the Data type of the Index column is whole number.


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

Hi @alfredorhz 
Please refer to attached file

1.png

3rolling = 
VAR CurrentIndex = Data[Index]
VAR OnAndBeforeTable = FILTER ( Data, Data[Index] <= CurrentIndex )
VAR Last3Table = TOPN ( 3, OnAndBeforeTable, [Index] )
RETURN
    IF ( 
        COUNTROWS ( Last3Table ) = 3,
        DIVIDE ( 
            SUMX ( Last3Table, [value1] ),
            SUMX ( Last3Table, [value2] )
        )
    )

HI @tamerj1 
Thanks for your support
May be I forgot write somenthing, Colum2 values is a calculate column, and I try to use the SELECTVALUE function but didn´t works, send me "the expresion refers to multiple colums" I don´t know if was usin the wrong funcion....

Hi @alfredorhz 

I just noticed your reply. Why do you need to use SELECTEDVALUE? It is irrelevant that Value2 is a calculated column, the code I proposed should work either ways. Did you try it? If so, what results did you get?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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