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 ?   
  • amitchandak's avatar
    4 years ago

    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] )