How to create a running total in Base for a Report

The Question

Given a Base table that contains a DATE column and a DECIMAL column, how would I accomplish a Report that contains a graph that reflects the accumulation of value (from the DECIMAL column) across time (as defined by the DATE column).

What are all of the pieces necessary, and how would they fit together?
If multiple viable approaches exist, what are the pros/cons?

Context

I’m migrating some calculations from a spreadsheet that they outgrew into Base. I need to figure out how to accomplish a “running total” or “running balance” for a graph on a Report.

For clarity, given the values `[5, -2, 3]`, the graph would show something like

``````6|       o-->
5| o--\  |
4|    |  |
3|    o--/
``````

My findings so far

OO forums: Problem in Per Row Computation - The gist of this thread is that referencing previous/next fields in SQL is extremely advanced, and you’re better off importing the data to a spreadsheet

LO Ask: Can we have calculated fields in LibreOffice Base? - SQL UPDATE and TRIGGER features can be used to make the equivalent of a formula cell

What I haven’t seen is anything about macros. From what I understand, macros/scripting are used to make entire enterprise applications on Access and Base, so I suspect that my best path forward might be to make a macro that is fired whenever the report is opened, and which iterates the table in order to populate a backing table that feeds the chart, though I’m not sure if there is a need for special queries or other elements, or if this could be done in memory so that a backing table is not necessary.

Since you want a chart based upon information you don’t have yet and this data is a cumulative figure, a macro is probably the best way to go.

If you have no experience in writing macros, this is a steep learning curve. Some information can be found in the LO documentation (click here) in Chapter 9 - Macros. Much more detailed information can be found in OOME by Andrew Pitonyak (PDF-click here).

There are two ways to generate a Chart in base - in Report Builder or displayed on a Form. Using a macro, generate this accumulated figure by reading existing data, and for each point required in the chart, save the appropriate information.

If the Chart is to be in Report Builder, as each point is generated, write a record out to a temporary table to be used within Report Builder. If the Chart is to be displayed on a form, the data is to be saved in an array. The completed array is passed to an area where the chart is created. For more information on creating a Chart in a Form, with working samples, see this post - click here.