Forum Discussion

heidibb's avatar
heidibb
Helper IV
6 years ago

Calculation over a moving window

Hello,

I have data that looks like the image below (the first 3 columns).

I am trying to creat a calculation that will sum over a rolling 6 terms... see "Rolling" column. Each value in the Rolling column will be a sum for that row + the previous 5 rows, so 6 rows total.

There has to be a way to achieve this with a measure, but I can't seem to figure it out.

Thanks so much!

8 Replies

  • heidibb try following

     

    Rolling 6 rows = 
    VAR __currRow = MAX ( Table[TermAxis] )
    VAR __startRow = _currRow - 5
    RETURN
    CALCULATE ( SUM ( Table[Value] ), Table[TermAxis] >= __startRow, Table[TermAxis] <= __currRow)

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    • heidibb's avatar
      heidibb
      Helper IV

      Thank you! It's  not quite working.

       

      I created a calculated measure using this per your example:

       

      The output for this is just the same value as the individual term value vs. the sum of the 6 terms

       

      • parry2k's avatar
        parry2k
        Super User

        heidibb interesting, I just tested at my end and it is working fine, not sure what we are missing here.