2022: Week 40 - Solution



Solution by Tom Prowse and you can download the workflow here.


This week we revisit the classic task from our school years - multiplication tables! Our task is to create a multiplication grid using an input that contains two rows - 1 & 9.

Step 1 - Create Rows

First up this week we need to pad the rows out so that we fill in the missing numbers between 1 & 9. We can do this using the Add Rows functionality within Tableau Prep with the following setup: 



This has allowed us to create a list of numbers from 1 to 9 



Step 2 - Different Combinations

Next we need to again pad out the rows, but this time we want to ensure that we have a row for each of the different combinations within our grid. For this we need to use a couple of different joins.

First, we can create a new clean step - we can use this as a self-join back to our New Rows step.

The first join is where all of the numbers are equal from both tables:


For the second join we want to do the opposite task... this time joining where the numbers do not equal the numbers from the other table: 


Both of these joins give us all of the different combinations that we will need for our multiplication table, so we can combine these using a union to get our complete table: 



Step 3 - Calculating the Multiplications

Now we have our table padded out with all of the different combinations, we can start to calculate the numbers for our table.

Total 
[Numbers]*[Numbers-1]

This gives us the numbers for our grid, so all we need to do now is organise them in the correct format.

Initially, we thought that you could just pivot these using a Rows to Columns pivot and we would be done. However... there seems to be an error with Tableau Prep where it doesn't like the pivot step next!

Therefore, at this stage we need to output our data and then bring it into a separate workflow. For the solution above I have used the same workflow but just changed the name/location of the Output and Input so I don't get any errors.

For the 'new' workflow, we can input our data then remove the Table Names field. 

We then want to pivot the data using a Rows to Columns pivot where we are pivoting the Numbers-1 field and Sum Total:



This gets our table in the correct shape and format. 

The only other task is to tidy up the table and order it correctly. 

To do this we can use a Rank analytical calculation using the Numbers field: 



As a result we are then ready to output our data that should look like this: 


You can download the full output here

After you finish the challenge make sure to fill in the participation tracker, then share your solution on Twitter using #PreppinData and tagging @Datajedininja@JennyMartinDS14 & @TomProwse1

You can also post your solution on the Tableau Forum where we have a Preppin' Data community page. Post your solutions and ask questions if you need any help! 

Popular posts from this blog

2023: Week 1 The Data Source Bank

2023: Week 2 - International Bank Account Numbers

How to...Handle Free Text