Results 1 to 6 of 6
  1. #1
    jabarlee is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    49

    Transpose table

    Hi everyone.



    I have the following table:
    tbl_LabResults

    Result_ID
    Result_Date
    Patient_ID
    LabTest_ID
    LabTest_Units
    LabTest_Value
    1 Date_1 Pt1 Test1 yyyy 6,7
    2 Date_2 Pt2 Test2 xxxx 8,5
    3 Date_3 Pt1 Test2 xxxx 4,4
    4 Date_2 Pt3 Test3 zzzz 3,2

    What I would like to do is to transform it like that:

    Result_ID Patient_ID LabTest_ID LabTest_Units Date_1 Date_2 Date_3
    1 Pt1 Test1 yyyy 6,7
    2 Pt2 Test2 xxxx 8,5
    3 Pt1 Test2 xxxx 4,4
    4 Pt3 Test3 zzzz 3,2

    By searching a little, I understand that I should use a normalizing UNION ALL query and a TRANSFORM query, probably with First, or something like that.
    I have tried to make it work, with no success.
    Could anyone help ?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    that sounds like the way to to do it.
    did you 1st get the Union query to work?

    once you do that , then make the crosstab query (that uses the Union Qry as source). Use the qry wizard.

    once that is done, alter the Crosstab query and make sure its set to FIRST, instead of Sum.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    UNION queries are only needed where you want to 'combine' the results from separate tables so not needed here.
    A crosstab will get what you want assuming the commas in lab test value are decimal separators and not multivalue fields.

    Use the first four columns as your column heading fields. Result_Date as your row heading and lab_test_value as your Values using First as you suggested
    The crosstab query wizard will make this easy to do.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    jabarlee is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    49
    Thank you for your answers.

    Colin, I assume that you meant to use the first (three, it does not allow more than 3) columns as row headings and Result_Date as column heading ? I tried that and it does return the result I am looking for, at least it seems so.

    Since I cannot use more than 3 row headings I'll use a query to concatenate LabTest_ID and LabTest_Units

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    The wizard only allows three row headings but you can add more in query design view.
    AFAIK there is no limit if done that way
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    jabarlee is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    49
    Yay! and thanx again!

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

Similar Threads

  1. Transpose a table using query in Access
    By Skhaliq in forum Access
    Replies: 1
    Last Post: 03-22-2018, 01:02 PM
  2. Transpose the data
    By deepakes2 in forum Access
    Replies: 6
    Last Post: 07-11-2016, 01:27 PM
  3. Transpose Data of single table
    By Atif Mahmood in forum Access
    Replies: 4
    Last Post: 05-05-2016, 04:50 AM
  4. Transpose SQL to VBA
    By McArthurGDM in forum Programming
    Replies: 8
    Last Post: 11-03-2015, 10:21 AM
  5. Transpose specific records to table (VBA)
    By KP_SoCal in forum Programming
    Replies: 2
    Last Post: 02-27-2013, 09:31 PM

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