Forum Discussion

Jyu1994's avatar
Jyu1994
Regular Visitor
1 year ago
Solved

Caculated column: Sum previous 3 rows

Dear all,    I have this set of data, I need to add a calculated column summing "Mvs" from the previous 3 rows. Any idea?     FFor example, the new columns shoul look like this:  Index...
  • Shahid12523's avatar
    1 year ago

    SumPrev3Mvs =
    VAR i = 'YourTable'[Index]
    RETURN
    CALCULATE(
    SUM('YourTable'[Mvs]),
    FILTER('YourTable', 'YourTable'[Index] >= i - 3 && 'YourTable'[Index] < i)
    )


    Adds a column that sums Mvs from the previous 3 rows based on Index.
    Works great for sequential data like yours.