Using The SQL MODEL Clause To Generate Financial Statements
One of our clients that I worked at recently had a rather tricky report that they wanted me to help with. At present, the report was put together using Excel, and looked something like this:
The report consisted of two sections, the top section being the actual, budget and variance figures for a department, and the bottom section being a set of percentages based on the top section. The first line of the report, net sales, was a memorandum item detailing the net sales for the department. The next two lines, gross profit and other income were then added together by a spreadsheet formula to give the next line, total net income. Next, wage costs, rent costs and other costs were totalled to give total costs, with the figure for total costs then being subtracted from total net income to give net contribution. The percentages at the bottom of the report were then calculated using these figures. Finally, variances were calculated, again using an Excel formula, for each of the line items.
As well as producing a report for each department, the client also wanted to produce another copy, this time for the company as a whole and derived from the figures in the department level reports. The figures in the top half of the report would need to be summed, whilst the percentages in the bottom half would need to be averaged.
The client had tried to produce the report using Discoverer and an account hierarchy, but the figures wouldn't add up properly. Fundamentally, you can't (easily) produce this sort of report in a tool like Discoverer because of all the inter-row calculations that are going on - the figures for row 4 are the sum of row 2 and 3, the figures for row 12 are the sum of rows 5 to 7 divided by row 1, and so on. Now they could write some PL/SQL code that would load the data into a PL/SQL collection and then process each figure individually, but a thought that came to mind when we were discussing it was to try out the new SQL MODEL clause.
For the full article, read on here.