Results 1 to 11 of 11
  1. #1
    mmanzo1001 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    3

    Multiplying two tables question

    What's the most efficient way to multiply out two tables given the attached example. I've got this going in excel and it's getting to be too large as Table two is 50 rows by 100+ columns.



    Not really sure what you would call this, matrix multiplication, cross join?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    That certainly has the look and feel of matrix multiplication. A challenge I had to face with my project. Your choices are to use the Excel matrix functions in VBA code or to program the algorithm in VBA. Both require arrays.

    My project also required inverse matrix calc. I found VBA code for matrix calcs from http://vplevris.com/

    Here is example of Excel matrix function in VBA http://www.ozgrid.com/forum/showthre...t=11967&page=1

    I discovered that matrix calcs in VBA with either method produced slightly different results than the calc in Excel spreadsheet.
    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.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Well your tables are not normalized which is causing you a problem. I'm including an example of how you can do what you want with both a non-normalized table and a normalized table. I would really strongly recommend you opt for the normalization simply because it's better able to handle change over time.

    The UNION query is what you would use for your current structure.

    The CROSSTAB query is what you would use for a normalized structure.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    rpeare, good point about the normalization. I knew there was something else I should have mentioned.

    However, rpeare, in your example db, tblProjects and tblProjects_Normalized are identical. Also Qry_SingleProject and Qry_AllProjects_Union are throwing input parameter prompts.
    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
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    I should also point out that the example you presents does not include all of the information required to logically generate the output you want.

    Table1 refers to Project 1
    Table 2 refers to Project Type A

    Nowhere do you provide information about which type (A, B or C) Project 1 is. Same for projects 2 and 3.

    If you want access to give you an answer, you must supply each piece of information required to logically come up with that answer.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Craig, it's called a cartesian join and while it's not the best way to do things sometimes it's the most efficient.

    Attached is a fixed copy, I must have done a save instead of a save as when I copied the table.

    Here's a fresh copy, the two 'final' queries aren't exactly what you asked for but you can play with them to get what you want.

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by CraigDolphin View Post
    I should also point out that the example you presents does not include all of the information required to logically generate the output you want.

    Table1 refers to Project 1
    Table 2 refers to Project Type A

    Nowhere do you provide information about which type (A, B or C) Project 1 is. Same for projects 2 and 3.

    If you want access to give you an answer, you must supply each piece of information required to logically come up with that answer.
    Craig, when did you show up here? Get tired of things over at AWF, did ya?

  8. #8
    mmanzo1001 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    3
    rpeare,

    Thanks a ton for taking the time to look at this; I know you don't have to. Apologies if the program/project nomenclature was confusing.

    In reality the first table is People and what percent of you time has gone to the following Pojects, these should total 100% across (looks like person1 does not currently!).

    The second table is a wieght factor table who's columns corespond to the projects above. The goal is to multiply out Table 1 by Weight A or in this case Project Type A, then B etc and finally sum by person.

    With that said, I'm going to keep looking at this, thanks again, but I was expecting 15 lines of output, not 45 so I'm not sure this is quite there yet.


    Quote Originally Posted by rpeare View Post
    Craig, it's called a cartesian join and while it's not the best way to do things sometimes it's the most efficient.

    Attached is a fixed copy, I must have done a save instead of a save as when I copied the table.

    Here's a fresh copy, the two 'final' queries aren't exactly what you asked for but you can play with them to get what you want.

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I gave you queries that would show you all of the data in the database, it's not limiting it in any way. Are you saying that in your first table PROJECT1 only relates to the project type A in the second table?

    My assumption based on your description that for every PERSON would have a resulting table for every value in the tblPrograms table. So 5x9 (3x3 matrix) = 45

    If your PROGRAM1 does correspond only to the item labeled A in the PROJECTS table you have even more reason to normalize your tables because you need a common criteria as Craig said you would need to establish a link between the tables if a specific column in one table is supposed to refer to a specific row in a second table.

    Here's an updated version of your database based on that assumption.

  10. #10
    mmanzo1001 is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    3
    Quote Originally Posted by rpeare View Post
    Here's an updated version of your database based on that assumption.

    Well this is just fantastic!

  11. #11
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Quote Originally Posted by ajetrumpet View Post
    Craig, when did you show up here? Get tired of things over at AWF, did ya?
    Ha!

    Actually, blame Bob. He spotted a fish biologist needing help here and PM'ed me to come over and help. I was active here briefly a long while ago but I got way too busy with work, and pretty burned out with AWF, and mostly gave up on assisting folks for a while.

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

Similar Threads

  1. Replies: 1
    Last Post: 04-28-2011, 08:09 AM
  2. Multiplying Values from a form and table
    By Lxmanager in forum Access
    Replies: 5
    Last Post: 02-19-2011, 07:07 PM
  3. Question About Temp Tables
    By Rawb in forum Database Design
    Replies: 4
    Last Post: 11-29-2010, 10:57 AM
  4. Multiplying
    By chazcoral2 in forum Forms
    Replies: 16
    Last Post: 09-10-2010, 01:44 PM
  5. database and tables question
    By aaronlalonde in forum Database Design
    Replies: 0
    Last Post: 08-03-2009, 06:51 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