Cross Join is also called Cartesian Join. It's named after the great French philosopher and mathematician René Descartes. The original spelling of his family name is in two words: Des Cartes, therefore Cartesian. Among many great inventions, he is well known for saying: I think therefore I am (Je pense donc je suis).
Cross Join is quite useful in data manipulation in creating Sigmoid/Spline based charts (Sankey for example), data scaffolding and many other applications.

Some may wonder why Tableau doesn't offer Cross Join within its join interface. I guess that it's because there are so many ways we can do it already. Here let me summarize them here.

1.Via Custom SQL with Union
Assume we want to cross join two tables: A and B. This works when one of the 2 tables is smaller with just a few rows (and a few columns). Assume here B has only 2 rows and 1 column:
Let's open Table A (Orders table in Superstore data set) in Excel file via Legacy Connection. This gives us the option to write Custom SQL.
This creates the cross join between the two tables! This is an application in creating Sigmoid curve.

If B has more rows, we just need to add more such unions. If B has more columns, we need to explicitly spell them out for each and every element of the columns in the query.

As we mentioned before, this approach is good if B is small.

2.Via Custom SQL with Excel
Once I needed to create a table structure via cross join for scaffolding. Then I put the tables into separate sheets in one Excel file. Opening it via legacy connection and using Custom SQL, I am able to cross join them easily.

Select * from [Date$],[Product Category$],[Customer Segment$]

This approach is fairly universal and only needs a single line of SQL code.

3.Via Tableau's Native Inner Join Dialog
Zen Master Jeffrey Shaffer described this cross join approach early on. Kettan wrote a great tutorial by creating an extra identical Join Key column in each joining table. The Join Key column can be populated with the same number such as 1 or the same string such as 'Join'.

4.Via Tableau Join Calculation (Tableau 10.2+) (See updates in comments)
This approach doesn't need SQL nor pre-populated Join Key column. No need to reshape data. This can work across different data sources. It's the most versatile approach.

In Tableau 10.2+, we can use "Join Calculation" to create Join Keys in both joining tables. Here we created '1' column in both tables. Note that only the first Join Key can be 1, while the other has to be generated using a formula. The dialog just doesn't let me to enter 1 in both Join Calculations. No need of pre-populated Join Key any more.
I was told by Zen Master Chris Love that Bethany Lyons of Tableau demoed something similar at Tableau Conference 2016. After viewing the video, I found that she used Join Calculation in one table, and pre-populated the other table with a Join Key column. It works as well.

Voila, a little review of the four approaches for Cross Join in Tableau. Pick the one that's appropriate for you. Let me know if you have different approaches.
2

View comments

  1. Hi Alex, great post! FYI the need for using a formula doesn't exist anymore, there was a problem during the 10.2 beta that prevented a join on two join calculations with both being 1 that was fixed for the initial 10.2.0 release.

    ReplyDelete
    Replies
    1. Thanks for the update! Now in the 4th approach, we can enter 1 in Joint Calculations for both data sources. This makes it even simpler to create cross join.

      Delete

(Refresh the page if you want to view the gif image multiple times. Or go to Tableau Public and click the button at the top-right corner.)

Jake and I collaborated on a dashboard. He told me that he learnt a way to create an in-place help page in Tableau. He first saw it at a conference somewhere and couldn't recall who the speaker was. So I am blogging here about it but the credit goes to somebody else. If anyone knows who the original creator is, leave a comment below.

The key idea is to float a semi transparent worksheet on top of the dashboard, where a help text box is strategically placed on top of each chart. This way, we can explain how to view each chart and what data points are important, etc. This worksheet is collapsible by a show/hide button. 

Below I would like to show how this worksheet can be constructed.

1. Sheet with a single data mark.

  • Double click the empty space in Marks panel and add two single quotes. Make the null pill a text label. This creates a single null mark.
  • Set the view as "Entire View"

2. Create an show/hide button

  • Go to the target dashboard
  • Drag a floating vertical container to the dashboard, making it cover all the area of interest.
  • Drag the Single Null Mark sheet and drop it into the above container. Hide the sheet title.
  • Create an open/close button for the container and place the button at the top-right corner.

3. Add annotations

  • Format the sheet background opacity as 70% in the layout manager             
  • Select area annotations and place them anywhere of interest. 
  • Write help text and format it to highlight important messages.  
  • The text can serve as functional guide and/or insight guide.

Here is an example. Feel free to download the workbook and explore. Click the "i" button at the top-right corner to view the in-place help. 

0

Add a comment

Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.