Results 1 to 6 of 6
  1. #1
    countingguru is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    17

    Convert a Matrix Table to a Vertical Table

    Dear Friends

    I am trying to convert a linked matrix excel worksheet to a Vertical tabulated sheet in Access with all the same content intact.
    Is there a code that can execute this conversion automatically?
    Or is there a query function that can perform this task as well?
    What is the best approach?
    Thanks in advance !

    The linked excel matrix table:

    Biz Unit: Unit 1 Unit 2 Unit 3 Unit 4 Sum
    Project: A 10% 90% 0% 0% 100%
    B 0% 40% 60% 0% 100%
    C 0% 10% 30% 60% 100%



    Converted Sheet:

    Project Biz Unit Pct


    A Unit 1 10%
    A Unit 2 90%
    B Unit 2 40%
    B Unit 3 60%
    C Unit 2 10%
    C Unit 3 30%
    C Unit 4 60%

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can use a UNION query to get that result.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    countingguru is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    17
    Quote Originally Posted by pbaldy View Post
    You can use a UNION query to get that result.
    Dear Baldy

    Can you script the union query please?

    Thanks

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    The matrix table looks odd. Is there a Header for the Project column?

    There is no wizard for UNION query, must type into the SQL window. The structure would be:

    SELECT "A" As Project, "Unit1" As BizUnit, [Unit 1] As Pct FROM tablename WHERE Project = "A"
    UNION SELECT "A", "Unit2", [Unit 2] FROM tablename WHERE Project = "A"
    UNION SELECT "B", "Unit2", [Unit 2] FROM tablename WHERE Project = "B"
    UNION SELECT "B", "Unit3", [Unit 3] FROM tablename WHERE Project = "B"
    UNION SELECT "C", "Unit2", [Unit 2] FROM tablename WHERE Project = "C"
    UNION SELECT "C", "Unit3", [Unit 3] FROM tablename WHERE Project = "C"
    UNION SELECT "C", "Unit4", [Unit 4] FROM tablename WHERE Project = "C";

    There is a limit of 50 lines in UNION.
    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.

  5. #5
    countingguru is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Posts
    17
    Yes. "Project" is the Header for the Project columns that have A,B,C.

    One question, how can I automate the SQL to consider all/any "Unit.." columns that have a value per each project....Despite of the fact that Project A (per illustration above) only has values for Unit 1 and 2.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Can't be dynamic. Include a UNION row for each project and UnitX regardless if percent is 0 or greater. So every project will have 4 UnitX rows. Are there only the 3 projects? Remember, only 50 lines in UNION query. Also, recordsets in VBA don't like UNION queries. I had to redesign a procedure to eliminate dependence on UNION query. The alternative is code to write records to a temp table.

    EDIT: I have since learned that must be DAO recordset to manipulate UNION query.
    Last edited by June7; 03-09-2014 at 04:40 AM.
    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. Query to Convert table
    By dhborchardt in forum Queries
    Replies: 3
    Last Post: 10-11-2012, 10:43 AM
  2. Replies: 6
    Last Post: 10-10-2012, 05:08 AM
  3. Replies: 2
    Last Post: 04-05-2012, 09:17 PM
  4. Replies: 1
    Last Post: 01-28-2011, 02:45 PM
  5. Convert form to Table or Add Field to Table
    By jlclark4 in forum Forms
    Replies: 1
    Last Post: 12-15-2010, 01:52 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