Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Rolling Sum for 4 previous rows based on ID

Hi, 

I'm looking to calculate the rolling sum for the current and the last 4 rows , based on an ID column.

Any help please ? 

 

  • Anonymous ,  Column or measure

     

    new column =
    Sumx(filter((Table), Table[ID] <= earlier(Table[ID]) && Table[ID] >= earlier(Table[ID]) -4) , [sales] )


    new measure =
    Sumx(filter(allselected(Table), Table[ID] <= Max(Table[ID]) && Table[ID] >= max(Table[ID]) -4) , [sales] )

2 Replies

  • Anonymous ,  Column or measure

     

    new column =
    Sumx(filter((Table), Table[ID] <= earlier(Table[ID]) && Table[ID] >= earlier(Table[ID]) -4) , [sales] )


    new measure =
    Sumx(filter(allselected(Table), Table[ID] <= Max(Table[ID]) && Table[ID] >= max(Table[ID]) -4) , [sales] )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thankyou so much for this solution, it helps to resolved my issues.