title: Spark aggregate function over range with skip or stride
body: <p>I'm trying to calculate an aggregate function like sum() over a window function with a range, BUT I only want to include every Nth row. AND what it skips should be relative to the front of the window (Always include the first row in the window)</p>
  
  <pre><code>//val df = some Dataframe {symbol,datetime,metric}
  val baseWin = Window.partitionBy("symbol").orderBy("datetime")
  
  //This is a plain sum over the window
  val plain = sum(col("metric")).over(baseWin.rowsBetween(-12,0))
  
  //This is ALMOST what I want (every 3rd) BUT isn't relative to the window
  val almost = sum(when(col("datetime")/lit(DAY) %3 === 0, col("metric")).over(baseWin.rowsBetween(-12,0))
  </code></pre>