The INLINE statement was just a way of loading some hardcoded data. It allows us to test that something works before hooking it up to the real data source. In this case, I don't have access to your data source, so it was a practical way of reproducing your data. It's also something that anyone could cut and paste to see that it works. Previous() looks at the row before this one in the source table. Rangesum(A,B) is just like doing A+B, except that if either is null, it treats them as 0, so that you still get the other value. That was necessary since the previous(AggregatedShoes) row on row 1 would return null. We don't need the rangesum() above because we're handling nulls differently. Here, if we're on row 1, the previous(Salesman) will be null, which is not the same as the current row's Salesman, so we return 0 explicitly. We do the same when the Salesman changes. But as long as we're within the same Salesman, each row subtracts the previous aggregation.