Results 1 to 10 of 10
  1. #1
    jobbie is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    46

    Query to get accounting balances

    I am running this query:
    Code:
    SELECT GL.Account_Name, Sum(Journal.Amount) AS Debit_Amount FROM GL INNER JOIN Journal ON GL.[Account_Name] = Journal.Debit_Ac
    GROUP BY GL.Account_Name
    which gives me the debit balance for the accounts in GL

    Table "Journal" has 3 columns [Debit_Ac],[Credit_Ac] and [Amount]

    Table "GL" has 1 column [Account_Name]

    Now I would like the query to also display the credit balance as separate column and also another column to show the difference between the credit and debit.

    I am using MS access 2007

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    doesn't look like your data is normalised, so you would need to use a union query to union the above query to a similar one linked to Journal.Credit_Ac

    Suggest you review your table design so this sort of thing becomes much simpler

  3. #3
    jobbie is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    46
    Quote Originally Posted by Ajax View Post
    doesn't look like your data is normalised, so you would need to use a union query to union the above query to a similar one linked to Journal.Credit_Ac

    Suggest you review your table design so this sort of thing becomes much simpler
    not sure how I could make my table design simpler than this. Can you please give me some tips?

    Also wouldn't using a union query place all the records in the existing columns instead of creating a new one for credit balances?

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    without seeing your full table design, difficult to say but I would design this

    Table "Journal" has 3 columns [Debit_Ac],[Credit_Ac] and [Amount]

    as

    Table "Journal" has 3 columns [Account_Name],[Account_Type] and [Amount]

    Where Account_Type would be Debit or Credit

    then you would use a crosstab query with accountname as rowheader, accounttype as column header and amount as value

    Also wouldn't using a union query place all the records in the existing columns
    you would need to create two columns

    Code:
    SELECT GL.Account_Name, Sum(Journal.Amount) AS Debit_Amount, 0 AS Credit_Amount FROM GL INNER JOIN Journal ON GL.[Account_Name] = Journal.Debit_Ac
    GROUP BY GL.Account_Name
    UNION SELECT GL.Account_Name, 0 AS Debit_Amount, Sum(Journal.Amount) AS Credit_Amount FROM GL INNER JOIN Journal ON GL.[Account_Name] = Journal.Credit_Ac
    GROUP BY GL.Account_Name

  5. #5
    jobbie is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    46
    Quote Originally Posted by Ajax View Post
    without seeing your full table design, difficult to say but I would design this

    Table "Journal" has 3 columns [Debit_Ac],[Credit_Ac] and [Amount]

    as

    Table "Journal" has 3 columns [Account_Name],[Account_Type] and [Amount]

    Where Account_Type would be Debit or Credit

    then you would use a crosstab query with accountname as rowheader, accounttype as column header and amount as value

    you would need to create two columns

    Code:
    SELECT GL.Account_Name, Sum(Journal.Amount) AS Debit_Amount, 0 AS Credit_Amount FROM GL INNER JOIN Journal ON GL.[Account_Name] = Journal.Debit_Ac
    GROUP BY GL.Account_Name
    UNION SELECT GL.Account_Name, 0 AS Debit_Amount, Sum(Journal.Amount) AS Credit_Amount FROM GL INNER JOIN Journal ON GL.[Account_Name] = Journal.Credit_Ac
    GROUP BY GL.Account_Name
    Don't mean to offend you but do you know accounting? Because it seems this may not work as in accounting when there is a debit entry there is also a corresponding credit entry to another account.

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    err - yes - I'm a FCMA/CGMA and been CFO/CFC of multinational companies. I now work as a consultant to companies large and small designing and often building cross system financial control systems typically required as a result of acquisitions, change of systems or regulatory change. I did say without seeing your full table design, difficult to say.


  7. #7
    jobbie is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    46
    Quote Originally Posted by Ajax View Post
    err - yes - I'm a FCMA/CGMA and been CFO/CFC of multinational companies. I now work as a consultant to companies large and small designing and often building cross system financial control systems typically required as a result of acquisitions, change of systems or regulatory change. I did say without seeing your full table design, difficult to say.

    ok my apologies but my intention was not to offend you.

    Actually I was able to solve the problem by using 2 separate queries as per your suggestion. If anything else comes up I will post it here. I won't mark the post as solved until then. Thanks


  8. #8
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    no offence taken

  9. #9
    jobbie is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    46
    ok so now I am facing an obstacle. I have the following queries:

    Debit_Balances:

    Code:
    SELECT GL.Account_Name, sum(nz([Journal].[Amount],0)) AS Debit_AmountFROM GL LEFT JOIN Journal ON GL.Account_Name = Journal.Debit_Ac
    GROUP BY GL.Account_Name
    HAVING ((GL.Account_Name)=[Forms]![Balance_sheet]![Text0]);
    Credit_Balances:

    Code:
    SELECT GL.Account_Name, nz(Sum([Journal].[Amount])) AS Credit_Amount
    FROM GL LEFT JOIN Journal ON GL.Account_Name = Journal.Credit_Ac
    GROUP BY GL.Account_Name
    HAVING (((GL.Account_Name)=[Forms]![Balance_sheet]![Text0]));
    and

    Final_Query:

    Code:
    SELECT Credit_Balances.Credit_Amount, Debit_Balances.Debit_Amount
    FROM Credit_Balances INNER JOIN Debit_Balances ON Credit_Balances.Account_Name = Debit_Balances.Account_Name;
    but Final_Query returns blank columns

    I would like to find the difference between the Debit and Credit amounts in the above 2 queries in a 3rd query

  10. #10
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    do your first two queries both produce values?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Calculating balances based on amounts in a table
    By A kinason in forum Reports
    Replies: 3
    Last Post: 05-09-2013, 10:25 PM
  2. Fee Calculation with Previous balances
    By jalals in forum Programming
    Replies: 14
    Last Post: 04-26-2013, 11:06 AM
  3. Replies: 8
    Last Post: 12-12-2012, 02:39 PM
  4. Beginning and balances in Access 2007
    By jalovingood in forum Access
    Replies: 1
    Last Post: 04-19-2011, 03:34 PM
  5. Accounting Template
    By mastromb in forum Access
    Replies: 4
    Last Post: 02-24-2010, 10:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums