Forum Discussion
rolling 3 values sum
Hi Cummunity
Could please help me with rolling 3 values whitout dates, for example
Operation = value1/value2
Thanks a lot
Hi alfredorhz
Please refer to attached file3rolling = 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] ) ) )
6 Replies
- tamerj1Community Champion
Hi alfredorhz
Please refer to attached file3rolling = 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] ) ) )- alfredorhzHelper I
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....- tamerj1Community Champion
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?
- Ashish_MathurSuper 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.
- alfredorhzHelper I
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?
- Ashish_MathurSuper User
Hi,
In the Query Editor, ensure that the Data type of the Index column is whole number.