Results 1 to 2 of 2
  1. #1
    jcarstens is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2012
    Posts
    6

    Change data in column to row fields

    I have a query in a database that I am trying switch the data from column 1 to be the fields for the query.



    I have attached an example.

    Query1AVG has the following fields:

    DateRange, AvgOfQuestion1, AvgOfQuestion2, AvgOfQuestion3, AvgOfQuestion4, AvgOfQuestion5

    With data as follows:

    Range1, some #, some #, some #, some #, some #
    Range2, some #, some #, some #, some #, some #
    Range3, some #, some #, some #, some #, some #
    Range4, some #, some #, some #, some #, some #
    Range5, some #, some #, some #, some #, some #

    I am trying to figure out how to swap the row/column to achieve the following layout:

    Fields: Range1, Range2, Range3, Range4, Range5

    With data being:

    AvgOfQuestion1, some#, some #, some #, Some #, some #
    AvgOfQuestion2, some#, some #, some #, Some #, some #
    AvgOfQuestion3, some#, some #, some #, Some #, some #
    AvgOfQuestion4, some#, some #, some #, Some #, some #
    AvgOfQuestion5, some#, some #, some #, Some #, some #

    This will be a query which will populate a report, so will need to be run frequently.

    Any help on this is greatly appreciatedDatabase2.accdb.zip

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    This would be easier if the data in Table1 was structured like:
    TestDate QuestionData QuestionID
    12/5/2012 23 1
    12/5/2012 12 5
    12/5/2012 65 3
    12/5/2012 54 2
    12/5/2012 23 4

    Then could do the table join and a CROSSTAB query.

    Your data can be rearranged into this structure with a UNION query.

    SELECT ID, TestDate, "Question1" As QuestionID, Question1 As QuestionData FROM Table1
    UNION SELECT ID, TestDate, "Question2", Question2 FROM Table1
    UNION SELECT ID, TestDate, "Question3", Question3 FROM Table1
    UNION SELECT ID, TestDate, "Question4", Question4 FROM Table1
    UNION SELECT ID, TestDate, "Question5", Question5 FROM Table1;
    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.

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

Similar Threads

  1. Cannot change column title
    By Ancient Dragon in forum Access
    Replies: 3
    Last Post: 11-12-2012, 08:44 PM
  2. Macro to change column name
    By jadog in forum Programming
    Replies: 2
    Last Post: 10-13-2012, 07:23 AM
  3. Change color on text using column value?
    By PoorCadaver in forum Programming
    Replies: 5
    Last Post: 03-02-2012, 09:52 AM
  4. Replies: 1
    Last Post: 12-08-2011, 08:03 AM
  5. Replies: 1
    Last Post: 08-18-2011, 08:35 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