Results 1 to 5 of 5
  1. #1
    foma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    3

    Question Crosstab - help with what should be a simply crosstab

    given data from a table in the form of:

    uid state oth_uid
    101 cat1 1
    101 cat2 2
    102 cat1 3
    103 cat1 4
    104 cat1 5
    104 cat1 6
    104 cat1 7
    104 cat1 8
    104 cat1 9
    104 cat2 10
    105 cat2 11

    I need results from a crosstab in the form of:

    Type Cat1 Cat2 Total
    Total Recs 8 3 11
    Unique Recs 4 3 5

    I can run a crosstab query to get one line of the above, but not the other. Not only don't I know how to transform this into two rows, I don't know how to limit the 2nd row to unique uid's. Help please.



    TRANSFORM Count(db.uid) AS CountOfid
    SELECT "Total Recs" AS hdr
    FROM db
    GROUP BY "Total Recs"
    PIVOT IIf([state]="cat1","Cat1,"Cat2");

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    did you use the crosstab wizard? if so, it would have asked you what fields to put as row items,
    your answer would have been UID.
    then columns, you would click STATE.

    use the wizard and always get it right.

  3. #3
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    I've had to do this before in Access. What I ended up doing was creating two queries and a table to assist in getting my result.
    The first query was a create table query which took the first Crosstab and generated the Total Recs row only (and in doing so the data structure for the table).
    The second query was an append query which took the second Crosstab which generated the Unique Recs row only and appended it to the table just created.
    Then my report used this output table which I constantly recreated.

    the button to run the report would run the make table query, then the append query, before opening the report.

    Good luck,


    Jeff

  4. #4
    foma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    3
    Quote Originally Posted by ranman256 View Post
    did you use the crosstab wizard? if so, it would have asked you what fields to put as row items,
    your answer would have been UID.
    then columns, you would click STATE.

    use the wizard and always get it right.
    @ranman256, Thanks for the quick help attempt. Yes, I used the wizard this time. No, it didn't produce the desired results with those field choices. I'm an old coder and even know sql to a fair degree. Access's innerds aren't fully sql compliant and I have to do this project in Access. So I dinked around entirely too long to try to get the results requested and got stuck.

    I like how responsive this forum is, though.

    Thanks again for trying.

  5. #5
    foma is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    3
    Quote Originally Posted by InsuranceGuy View Post
    I've had to do this before in Access. What I ended up doing was creating two queries and a table to assist in getting my result.
    The first query was a create table query which took the first Crosstab and generated the Total Recs row only (and in doing so the data structure for the table).
    The second query was an append query which took the second Crosstab which generated the Unique Recs row only and appended it to the table just created.
    Then my report used this output table which I constantly recreated.

    the button to run the report would run the make table query, then the append query, before opening the report.

    Good luck,


    Jeff
    @InsuranceGuy Thanks for responding. I'd briefly thought about making pre-queries, but was just insisting that I find an elegant solution all in a single crosstab. Naivete, I suppose. This project will require a rather large amount of duplicated efforts and I was hoping to minimize that effort by getting it all done in one query. Oh well. Thanks for the tip. I'll buckle down and go the route of multiple queries.

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

Similar Threads

  1. crosstab query
    By barkarlo in forum Queries
    Replies: 5
    Last Post: 02-25-2013, 08:35 AM
  2. Crosstab?
    By justin1681 in forum Access
    Replies: 3
    Last Post: 06-27-2012, 12:41 PM
  3. Crosstab example
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 12:07 AM
  4. Crosstab Query
    By lukewarmbeer in forum Access
    Replies: 2
    Last Post: 08-13-2010, 05:10 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