2023: Week 37 - Solution



Solution by Tom Prowse and you can download the workflow here



This week we are looking at how we can create sequences and orders within a table when there isn't a field that is already available. 

Step 1 - Input Data

First we want to input both tables from the given output. This contains orders for July & August and we want to union these together so that they're in a single table that looks like this: 


We can then use the Table Names field to extract the month name from the string of text. We can utilise Tableau Prep's feature to use the automatic split which will bring the month name into a separate field. 


Then we can add the year to the month using a string calculation: 

Date
[Month]+" 2023"

Then we can update the field type to a date and our table should look like this: 



Step 2 - Sequence ID

Now we have a date we can now start to create the sequence by using a rank calculation. We need to create the date as a source row number is created for both the July & August table, therefore creating a repeating row number. 

By utilising the date and source row number we can create a rank calculation: 

Sequence ID


Here we group by the whole table, then order by the date and source row number to create the rank. This ignores the original row source number and creates a running row number across the whole table:



Step 3 - Bigger Order?

Finally we want to create a field to highlight whether the current order is larger than the previous one. Again, we can utilise the analytical calculations in Tableau and this time we use the Difference From calculation to group by Book & Customer, order by Sequence ID, then compute using Quantity.



This gives us the final field that we need and our output will look like this: 



You can download the output from 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