Solved

Union Query help

Posted on 2016-08-19
2
56 Views
Last Modified: 2016-08-20
I have 2 data imports from excel.
I have a union query that correctly sums the data  [ImportAP].[Amount in Local Curr] and [ImportAR].[ExpectedAmontAR] (its groups and shows the balance between these two fields) but now I need to add a separate sum that shows the sum for [ImportAP].[Amount in Local Curr] and  [ImportAR].[ExpectedAmontAR] ...basically showing the amounts the query uses to arrive at the sum balance.  I would need to extra columns to show the separate amounts of ImportAP].[Amount in Local Curr] and  [ImportAR].[ExpectedAmontAR] and I do have these columns in the query I made but the amounts dont appear.  I think you will see where I went wrong once you open the query entitled "doesnt work".  

I have attached a file with the 2 separate imports from excel and the query that correctly sums and the one I have made to sum the separate amounts as described above.  

thank you for your help.
ExcelImport.accdb
0
Comment
Question by:pdvsa
2 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41763442
You went half the way as you need dummy values for the "missing" column in both selects in the union query. So try this:
SELECT 
    A.YearMon, 
    Sum(A.SumAmount) AS Total, 
    Sum(A.SumAP) AS SumAP, 
    Sum(A.SumAR) AS SumAR
FROM 
    (SELECT 
        Format([Net due dt],"yyyy mm") AS YearMon, 
        Sum(ImportAP.[Amount in local cur]) AS SumAmount, 
        Sum(ImportAP.[Amount in local cur]) as SumAP, 
        0 As SumAR
    FROM 
        ImportAP
    GROUP BY 
        Format([Net due dt],"yyyy mm")
    Union ALL
    SELECT 
        Format([BegOfWeekDate],"yyyy mm") AS YearMon, 
        Sum(ImportAR.ExpectedAmtRec) AS SumAmount, 
        0 As SumAP, 
        Sum(ImportAR.ExpectedAmtRec) as SumAR
    FROM 
        ImportAR
    GROUP BY 
        Format([BegOfWeekDate],"yyyy mm")
     )  AS A
GROUP BY 
       A.YearMon;

Open in new window

/gustav
0
 

Author Closing Comment

by:pdvsa
ID: 41763460
nice.  very nice.  dummy column gotcha again.  SA is interesting.  Not much to do so all i do is work.  :)
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question