Share via

Create a 2 year comparison report

Anonymous
2012-07-17T05:55:37+00:00

I would like to create a 2 year annual comparison report using financial data from a single table.  The data is based on a many to many relationship as there may be accounts used in eg: 2011 that will not be used in eg: 2012, and vice versa. I have created separate queries that return the desired data for each year, but can't seem to join them correctly to make it work in the report.

The report should list all account names in the left most column.  Column headings should be eg: 2011 and 2012.  The total annual amount for each account should fill the appropriate year heading.

Non of the available joins do the trick if I add the 2 queries into one query.

So far what I have attempted with make table queries and a junction table has not worked. Make table doesn't like that much.

Using Access 2007.

Any help would be greatly appreciated.

Connie

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2012-07-17T06:13:32+00:00

You could create a union query AllAccountNames that returns all account names:

SELECT [AccountName] FROM [QueryFor2011]

UNION

SELECT [AccountName] FROM [QueryFor2012]

Then create a new query like this:

SELECT [AllAccountNames].[AccountName], [QueryFor2011].[TotalAmount] AS Total2011, [QueryFor2012].[TotalAmount] AS Total2012

FROM [QueryFor2011] RIGHT JOIN ([AllAccountNames] LEFT JOIN [QueryFor2012] ON [AllAccountNames].[AccountName] = [QueryFor201].[AccountName]) ON [QueryFor2012].[AccountName] = [AllAccountNames].[AccountName]

Change the names to suit your situation.

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-07-18T14:59:57+00:00

    Hi Hans,

    Thanks for your help.  I have it figured out.  Someone added parentheses and it worked perfectly.

    Was this answer helpful?

    0 comments No comments
  2. HansV 462.6K Reputation points
    2012-07-18T05:27:46+00:00

    I don't understand why you have a PAST ACCT and CURR ACCT field in QryACAcctNames.

    Apart from that, it's best to create the second query in design view. Access will then take care of the details of the SQL for you.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-07-18T01:08:35+00:00

    I created the above queries.  The union query works perfectly.  However, the select query keeps giving me error messages. The below is the actual statement used.  Queries are all actual. 

    SELECT [QryACAcctNames].[PAST ACCT], [QryACPastYear].[PAST DEP] AS TOTPastDEP, [QryACCurrentYear].[CURR DEP] AS TOTCurrDEP

    FROM [QryACPastYear] RIGHT JOIN ([QryACAcctNames] LEFT JOIN [QryACCurrentYear] ON [QryACAcctNames].[PAST ACCT] = [QryACPastYear].[PAST ACCT]) ON [QryACCurrentYear].[CURR ACCT] = [QryACAcctNames].[CURR ACCT]

    When I attempt to save it, the message "Syntax error in Join Operation" pops up.

    Can you tell me what I'm doing wrong?

    Thx!!

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-07-17T06:28:22+00:00

    Thanks very much. I will try that!

    Was this answer helpful?

    0 comments No comments