Results 1 to 10 of 10
  1. #1
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283

    UNION Query issues with crosstab

    I have 2 queries, 1 that shows the data, and the other that sums the data. I am trying to Union them so I can get the data and then basically a subtotal of all the days of the month by rep. As this report will be run daily the number of columns (which is the date) will expand and contract.



    I can't seem to get the subtotal query to add to the data query.

    Here is my data query
    Code:
    TRANSFORM Nz(Count([Class]))+0 AS Expr1
    SELECT IIf([Employees] In ('CA047767','CA065354','CA047763','CA048935','CA065788','CA055115','CA055757'),'CND-ISS',IIf([Employees] In ('CA063571','CA069760','CA071053','CA069610','CA050708','CA068210','CA069997','CA065331'),'XCL-TELESALES','UNKNOWN')) AS Industry, LOGAN_ACTYS.[Created By Name], IIf([Class] In ("Cold Call","Closing Call","Exec Value Proposition / Call","Scheduled Sales Call"),"Customer Contact",IIf([Class] In ("Opportunity Plan","Networking / Industry Event"),"Business Development",[LOGAN_ACTYS].[Class])) AS Type, Nz(Count([Class]))+0 AS Total
    FROM LOGAN_ACTYS
    GROUP BY IIf([Employees] In ('CA047767','CA065354','CA047763','CA048935','CA065788','CA055115','CA055757'),'CND-ISS',IIf([Employees] In ('CA063571','CA069760','CA071053','CA069610','CA050708','CA068210','CA069997','CA065331'),'XCL-TELESALES','UNKNOWN')), LOGAN_ACTYS.[Created By Name], IIf([Class] In ("Cold Call","Closing Call","Exec Value Proposition / Call","Scheduled Sales Call"),"Customer Contact",IIf([Class] In ("Opportunity Plan","Networking / Industry Event"),"Business Development",[LOGAN_ACTYS].[Class]))
    PIVOT DateValue([Created]);
    and here is the summed query

    Code:
    TRANSFORM Nz(Count([Class]))+0 AS Expr1
    SELECT LOGAN_ACTYS.[Created By Name]
    FROM LOGAN_ACTYS
    GROUP BY LOGAN_ACTYS.[Created By Name]
    PIVOT DateValue([Created]);
    I added a screen shot of where I am trying to go as well. Any help would be appreciated.

    Click image for larger version. 

Name:	Capture.JPG 
Views:	15 
Size:	146.7 KB 
ID:	29252

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    you can always run the crosstab,
    pop it over to excel to do the sub totaling

  3. #3
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    Yeah I would prefer to get it all out of access if I could so I can eliminate the added touch points

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It is all to do with the sort order. In the first column for the summed query, concatenate industry name and "TOTAL", that will sort the total line to the bottom.

  5. #5
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    Quote Originally Posted by aytee111 View Post
    It is all to do with the sort order. In the first column for the summed query, concatenate industry name and "TOTAL", that will sort the total line to the bottom.

    ok I updated the summed query to look like this

    Code:
    TRANSFORM Nz(Count([Class]))+0 AS Expr1
    SELECT [Created By Name] & " " & "TOTAL" AS Expr2
    FROM LOGAN_ACTYS
    GROUP BY [Created By Name] & " " & "TOTAL"
    PIVOT DateValue([Created]);
    I am just not sure how to join them together.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    To join them use "UNION". Both queries have to have exactly the same number of fields.

    Syntax:
    SELECT * FROM crosstab_query
    UNION SELECT * FROM summed_query
    ORDER BY industry;

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Never seen a UNION of CROSSTAB queries but aytee's suggestion certainly looks doable.

    Building a stable report to run perpetually based on CROSSTAB is not easy, especially when pivoting on date values because of the dynamic nature of field names. Review http://allenbrowne.com/ser-67.html#ColHead
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    BTW, your totals query does not need to be a crosstab, you can bring in the crosstab query and do a totals query.

  9. #9
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    you might also find it better if you declare the crosstab heading

    change

    ...
    PIVOT DateValue([Created]);

    to

    ...PIVOT DateValue([Created]) IN (1,2,3);

    it might also be an idea to not use a straight date i.e. 04/07/2017. Use something like "D" & format(created,"yymmdd")

    as a column name it breaks all the rules about not starting with a number and including non alphanumeric characters

    You can always modify the labels in your form/report

  10. #10
    mindbender is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2013
    Posts
    283
    I don't know how you guys know all this stuff but all of this information was awesome. It is now working as expected.

    Thank you very much

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

Similar Threads

  1. Issues With Crosstab Forms & Sums
    By djclinton15 in forum Forms
    Replies: 1
    Last Post: 11-20-2016, 07:15 PM
  2. Replies: 2
    Last Post: 04-30-2014, 03:01 PM
  3. Union query to join two crosstab queries
    By racefan91 in forum Queries
    Replies: 5
    Last Post: 09-26-2013, 10:24 AM
  4. Union Query of 2 Crosstab
    By shawnjerome in forum Queries
    Replies: 1
    Last Post: 04-05-2012, 01:05 PM
  5. Union Crosstab
    By dssrun in forum Queries
    Replies: 2
    Last Post: 11-14-2011, 10:28 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