The challenge this week is looking at creating unique identifiers by combining fields and creating them with calculations.
Step 1 - Merge Order Dates
After inputting our data we want to ensure that we have a since column for our order date. Currently, this is split over three different fields so we want to merge these together.
First we need to ensure that all of the fields are a Date. This will allow us to then merge the fields selecting all three (holding down ctrl if you are using a Windows machine) then right click and select 'Merge'
After the merging our table will look like this:
Step 2 - Customer Initials
We can now start to create the unique identifier using the fields that we have in our data set. The unique identifier is made up of:
- Customer Initials
- Order Number
- 0's in between
First we can create the initials. As we have a single field that contains both First and Last name we first need to split these in separate fields (1 for First name, 1 for Last name).
We can use an automatic split for this:
Now we have the separated fields, we can use string calculations to combine the first initials from each:
After this calculation we can remove the split fields so that our table looks like this:
Step 3 - Order Number
The next part of our unique identifier is to create the padded order number. This will require us to create a field that is 6 digits long with the order number at the end and 0s making up the rest of the digits.
This process is called padding, and we can achieve this with the following calculation:
Padded Order Number
RIGHT(
'000000000'+STR([Order Number])
,6)
This allows us to first add all of the 0s, then limit the number of digits by using the Right function. As a result we get a 6 digit field that can be used as our padded order number:
Step 4- Order ID
The final step is to create the complete Order ID by combining the fields that we have just created. The order ID calculation looks like this:
Order ID [Customer Initials]+[Padded Order Number]
After this calculation we can remove the additional fields and our final output is ready:
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!
Created by: Carl Allchin Welcome to a New Year of Preppin' Data challenges. For anyone new to the challenges then let us give you an overview how the weekly challenge works. Each Wednesday the Preppin' crew (Jenny, myself or a guest contributor) drop a data set(s) that requires some reshaping and/or cleaning to get it ready for analysis. You can use any tool or language you want to do the reshaping (we build the challenges in Tableau Prep but love seeing different tools being learnt / tried). Share your solution on LinkedIn, Twitter/X, GitHub or the Tableau Forums Fill out our tracker so you can monitor your progress and involvement The following Tuesday we will post a written solution in Tableau Prep (thanks Tom) and a video walkthrough too (thanks Jenny) As with each January for the last few years, we'll set a number of challenges aimed at beginners. This is a great way to learn a number of fundamental data preparation skills or a chance to learn a new tool — New Year...
Created by: Carl Allchin Welcome to a New Year of Preppin' Data. These are weekly exercises to help you learn and develop data preparation skills. We publish the challenges on a Wednesday and share a solution the following Tuesday. You can take the challenges whenever you want and we love to see your solutions. With data preparation, there is never just one way to complete the tasks so sharing your solutions will help others learn too. Share on Twitter, LinkedIn, the Tableau Forums or wherever you want to too. Tag Jenny Martin, Tom Prowse or myself or just use the #PreppinData to share your solutions. The challenges are designed for learning Tableau Prep but we have a broad community who complete the challenges in R, Python, SQL, DBT, EasyMorph and many other tools. We love seeing people learn new tools so feel free to use whatever tools you want to complete the challenges. A New Year means we start afresh so January's challenges will be focused on beginners. We will u...
Free isn't always a good thing. In data, Free text is the example to state when proving that statements correct. However, lots of benefit can be gained from understanding data that has been entered in Free Text fields. What do we mean by Free Text? Free Text is the string based data that comes from allowing people to type answers in to systems and forms. The resulting data is normally stored within one column, with one answer per cell. As Free Text means the answer could be anything, this is what you get - absolutely anything. From expletives to slang, the words you will find in the data may be a challenge to interpret but the text is the closest way to collect the voice of your customer / employee. The Free Text field is likely to contain long, rambling sentences that can simply be analysed. If you count these fields, you are likely to have one of each entry each. Therefore, simply counting the entries will not provide anything meaningful to your analysis. The value is in ...