Search code examples
spotfire

Build a rolling sum across a date and attribute


I have weekly data for Products and Markets from an Information Link. I want to create a rolling 12 week sum across the Date AND the Market (in this instance, Product A is always Product A) as a Calculated Column. On other Information Links without a Market, I have used Sum([DOLLARS]) OVER (LastPeriods(12,[DATE])). Now, I need to do something like Sum([DOLLARS]) OVER ([MARKET1], LastPeriods(4,[WEEK_ENDING_DATE])), however I cannot figure out the exact syntax.

Below is an example of the data: enter image description here

In summary, I am trying to build a rolling sum column across a Date Hierarchy AND an attribute. The OVER syntax does not seem to support LastPeriods and an attribute together.


Solution

  • You need the Intersect keyword:

    Sum([DOLLARS]) OVER Intersect([MARKET1], LastPeriods(4,[WEEK_ENDING_DATE]))