Question

I need to develop a web app that allows companies to forecast financials.

the app has different screens, one for defining employee salaries, another for sales projections etc.. basically turn an excel financial forecast model into an app.

question is, what would be the best way to design the database, so that financial reports (e.g. a profit and loss statement or balance sheet) could be quickly generated?

  • assuming the forecast period is for 5 years, would you have a table with 5 years*12 months = 60 fields per each row? is that performant enough?
  • would you use DB triggers to recalculate salary expenses whenever a single employee data is changed?
Was it helpful?

Solution

I'd think it would be better to store each month's forecast in its own row in a table that looks like this

month   forecast
-----   --------
    1      30000
    2      31000
    3      28000
   ...       ...
    60     52000

Then you can use the aggregate functions to calculate forecast reports, discounted cash flow etc. ( Like if you want the un-discounted total for just 4 years): SELECT SUM(forecast) from FORECASTS where month=>1 and month<=48

For salary expenses, I would think that having a view that does calculations on the fly (or if you DB engine supports "materialized views" should have sufficient performance unless we're talking some giant number of employees or really slow DB.

Maybe have a salary history table, that trigger populates when employee data changes/payroll runs

employeeId    month   Salary
----------    -----   ------
         1        1     4000
         2        1     3000
         3        1     5000
         1        2     4100
         2        2     3100
         3        2     4800
       ...      ...      ...

Then again, you can do SUM or other aggregate function to get to the reported data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top