Storing summed values

best practicesdatabase-design

I'm trying to create a database to store values for Profit & Loss statements and I'm wondering what the best way to structure this would be. Specifically, amounts that are are equated from other numbers such as: operating income = gross income – operating expenses, and also operating expenses = wages + rent.

Should there be a field for each value, even if it is a result of an equation, or should I only keep the non-equated values, and equate the others when querying or pulling the data into a report?

In the former I would have to more fields and there's potential for the summed numbers to be entered incorrectly, the latter seems like it would have a complex structure, and would need complex queries. Keep in mind that the P&L statement I'm actually working with has many more accounts and summed accounts.

Is there a best practice for this, or place to get more info on this? I really appreciate the help

Best Answer

The correct answer is: it depends. Here are factors you should take into account:

  • is there any possibility of the figures changing? Accounts are sometimes restated. If you had a summary table you would have to change that as well if there was a restatement.
  • you say you are trying to create a database. Does this mean you already have an OLTP (online transaction processing) database and the new one would a data warehouse? If so then you need to research data warehouse schemas like the snowflake design and, more importantly, decide the key values you are tracking. One way of describing a data warehouse is one huge summary table. Reporting and analysis are often easier with summarized data.
  • or maybe you just want to add some tables to summarize the data and keep it in the same database as the source material. If so there are many other tools like views, materialized views that could be used that are dynamic.
  • there is a trade off between summarizing data. Once you take a snapshot you have to make sure it stays in sync with the real data. Or you can build a structure on top of the original data with views.
  • if the amount of data is small or can be broken into smaller parts you could fill a summary table with a procedure that marks each entry when it was created. Then if fiscal 2011 is restated due to whatever you just delete all fiscal 2011 entries from the summary table and rebuild with your procedure. This may or may not pass auditor standards depending on your location, your industry and your companies practices.
Related Question