# Running Total

• ### Question

• Is it possible to calculate a running total of values in SA?

I now I can always have large enough window and sum on that but can i pass the running total from previous window output to the next and count some form of running total of some value?

Regards

Thursday, April 28, 2016 12:33 PM

• The ASA language is designed to have a finite amount of state history. Running total’s state history is not bounded, so as long as we stay with the finite state history design principle, we cannot support running totals like you suggest.

You could output the aggregated counter to SQL (e.g. at 1 hour / day interval), and if you want to get total since some time, do a SQL query to sum them all up.

If this doesn't work for you then perhaps you could try externalizing long-living state. For, example you could be producing daily Tumbling Windows and writing them into dedicated output. You can consume the same output in the job itself. The real output will combine last known daily tumbling window and event aggregation since the beginning of the day.

Would be happy to discuss this further with you if you like.

Tuesday, June 28, 2016 5:19 PM

### All replies

• It would be good to understand your requirement a little deeper.

What is the scenario you need to enable?

Monday, June 27, 2016 9:36 PM
• The ASA language is designed to have a finite amount of state history. Running total’s state history is not bounded, so as long as we stay with the finite state history design principle, we cannot support running totals like you suggest.

You could output the aggregated counter to SQL (e.g. at 1 hour / day interval), and if you want to get total since some time, do a SQL query to sum them all up.

If this doesn't work for you then perhaps you could try externalizing long-living state. For, example you could be producing daily Tumbling Windows and writing them into dedicated output. You can consume the same output in the job itself. The real output will combine last known daily tumbling window and event aggregation since the beginning of the day.

Would be happy to discuss this further with you if you like.

Tuesday, June 28, 2016 5:19 PM
• Is there a way to get the difference between a column in 2 rows and guarantee it's sorted on a column that you specify as the event time? For instance, I have 2 columns, on is EventDateTime and the other is a meter value. I need to take the difference between the latest value and the earliest value and aggregate that down. I've been using a tumbling window, but that misses the event differences between the end of one window to the beginning of the next window. I've tried lag but that doesn't appear to guarantee sort order on my column datetime value. Any suggestions?
Thursday, October 19, 2017 3:16 PM