+ Reply to Thread
Results 1 to 5 of 5

Cartesian product / Cross join of two tables (possible solution with Power Query)

  1. #1
    Registered User
    Join Date
    06-19-2015
    Location
    Oslo
    MS-Off Ver
    2016
    Posts
    21

    Cartesian product / Cross join of two tables (possible solution with Power Query)

    I am wondering if it is possible to generate a third table from two tables which is the Cartesian product of the two. The attached Excel file illustrates my issue.

    Thanks in adavance!
    Attached Files Attached Files
    Last edited by p3rlend; 04-19-2016 at 07:33 PM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Cartesian product of two tables

    It can't be done, since the values are not in table 1 or table 2.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Cartesian product of two tables

    There's a workbook at https://app.box.com/s/47b28f19d794b25511be that will do this:

    B
    C
    2
    Name
    Month
    3
    4
    Alice Jan
    5
    Bob Feb
    6
    Mar
    7
    8
    Alice Jan
    9
    Alice Feb
    10
    Alice Mar
    11
    Bob Jan
    12
    Bob Feb
    13
    Bob Mar
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,949

    Re: Cartesian product of two tables

    First: I think it helps us help you if you define terms. I assume that this is what you mean by "Cartesian product" of two sets: https://en.wikipedia.org/wiki/Cartesian_product

    If so, then the difficult part is generating the different combinations:
    1,1
    1,2
    1,3
    2,1
    2,2
    2,3
    and so on.

    I am not aware of any "built in" solution for generating these combinations. Most solutions for generating combinations like that that I see are based on "For..Next" loops in a symbolic programming language like VBA. You should be able to find any number of examples around the internet. Once you have your list of combinations generated in the spreadsheet, then, you can simply use the INDEX() function to return each element of each set. https://support.office.com/en-us/art...2-b56b061328bd
    Please Login or Register  to view this content.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    06-19-2015
    Location
    Oslo
    MS-Off Ver
    2016
    Posts
    21

    Re: Cartesian product of two tables

    Thanks for the replies.

    VBA can be a solution, but I would prefer a more dynamic approach, if it exists.

    I have a solution to take the Cartesian product, or cross join as it is also called, by using Power Query. Here http://exceleratorbi.com.au/cross-jo...h-power-query/ the approach is described. The two tables in my spreadsheet are added via Power Query. Table1 are duplicated, and one column are added to this new table. In the new custom column the formula =[Table1] is added. Then the custom column are expanded. This gives us a cross join (or Cartesian product) of Table1 and Table2.

    The problem is to add a new input column in the spreadsheet to add more information to the new table (the cross join table). In the spreadsheet below, the Power Query tables are modelled, and one more column are added to the cross join table in the spreadsheet (not in the Power Query table). If we f.ex. add more months to Table2 in the spreadsheet and refresh the Power Query tables, the cross join table will update accordingly. But the information in the Hours column will not be consistent. The number that belongs to one person in a given month might change place to another person or another month.

    So I am wondering if it is a solution to this problem. Is there a way to create a cross join table with Power Query, and then add a new column to this table such that people can input hours worked?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 07-20-2015, 04:32 AM
  2. [SOLVED] Advanced Sum Product/SUMIF with multiple tables
    By pookyman in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-27-2014, 08:38 PM
  3. Cartesian Macro help!
    By katich in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-15-2014, 08:57 AM
  4. Transfer Data to separate tables based two variables (site and product)
    By yunesm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-15-2010, 09:47 PM
  5. Product Analysis in Pivot Tables
    By pensworth in forum Excel General
    Replies: 7
    Last Post: 03-24-2009, 11:10 AM
  6. [SOLVED] Cartesian chart
    By Zekni in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 05-13-2006, 08:15 PM
  7. Product Function in Pivot Tables from Multiple Consolidation Range
    By bbishop222 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-22-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1