Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: rboccuzziOk, I am not sure why you wouldn't want to run two aggs, one on the Date, Color, and then a second after the first, on the first's output, on just the date. You wouldn't have to sort again, and the meaning would be pretty straightforward and easy to follow.
If you really want to do it in one agg though, you could maybe do something where you agg on Date,Color, and you keep a running total, as well as do the subtotal for each date/color correctly. You are still going to be putting out all the rows, and you only know the date already changed, not that it was about to change, so you can't limit the output on another output, but the data is correct, if you look at the correct rows, if you follow.
Here is the code to do that:
if execCount == 1 then
lastDate = null
if execCount == 1 or lastDate != Date then
TotalPrice = 0
TotalSubPrice = sum(Price)
if lastInGroup then
TotalPrice = TotalPrice + TotalSubPrice
emit *, TotalPrice, TotalSubPrice
where lastInGroup
lastDate = Date
Cheers
Rich