Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to perform a cross join or Cartesian product in excel?

At the moment, I cannot use a typical database so am using excel temporarily. Any ideas?

The enter image description here

like image 739
user1248831 Avatar asked Nov 18 '14 16:11

user1248831


People also ask

Is Cross join same as Cartesian product?

The CROSS JOIN is used to generate a paired combination of each row of the first table with each row of the second table. This join type is also known as cartesian join.

What is cross join or Cartesian join?

The CARTESIAN JOIN or CROSS JOIN returns the Cartesian product of the sets of records from two or more joined tables. Thus, it equates to an inner join where the join-condition always evaluates to either True or where the join-condition is absent from the statement.

How do you create a Cartesian product in Power Query?

In Power Query you can apply a Cartesian product on any two tables by adding to the first table a custom column with a reference to the second table. Then, by expanding the new column, you will reach the Cartesian product.


1 Answers

You have 3 dimensions here: dim1 (ABC), dim2 (123), dim3 (XYZ).

Here is how you make a cartesian product of 2 dimensions using standard Excel and no VBA:

1) Plot dim1 vertically and dim2 horizontally. Concatenate dimension members on the intersections:

Step 1 - plotting dimensions

2) Unpivoting data. Launch pivot table wizard using ALT-D-P (don't hold ALT, press it once). Pick "Multiple consolidation ranges" --> create a single page.. --> Select all cells (including headers!) and add it to the list, press next.

step2 - unpivoting data

3) Plot the resulting values vertically and disassemble the concatenated strings

step 3 - disassemble strings

Voila, you've got the cross join. If you need another dimension added, repeat this algorithm again.

Cheers,

Constantine.

like image 144
BusinessAlchemist Avatar answered Oct 11 '22 02:10

BusinessAlchemist