Skip to content
Advertisement

How to sum Accounts

I have 3 tables: DimAccounts, DimTime and FactBudget.

DimAccounts example:

DimTime example:

FactBudget example:

In FactBudget are many Accounts just with type B. I need to calculate Debit and Credit Sums where Account type is S (Sum). Columns AccountFrom and AccountTo shows B Type Accounts from where to begin summing (AccountFrom ) and where end (AccountTo).

I have made solution using Cursors…. buth you know this is very bad 🙂 I think there somehow to Group data in FactBudget (because there also many columns in factbudget and rows 600k) and when search for solution (when I group left just 60k rows):

So, How to get S Accounts Debit and Cred Sum by TimeKey and AccountKey? (AccountKey datatype is nvarchar)

Solution example:

In Fact budget there is no Account with type S!!!! we need to get it (example 1.11000 just for date 20080523):

But I need each S Account Debit and credit Sum by date.

Advertisement

Answer

As far as I can see, you need to join DimAccounts to itself to associate B-type accounts with their corresponding S-type accounts, then join that row set to FactBudget to finally obtain the figures. Something like this:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement