How to... add in your data source name (automagically)

Tableau Prep Builder (as of version 2020.3) doesn't have a simple way to add the data source name or table name into your data set if it's not in the actual data set itself. But I've found a neat trick of how to achieve this!

The Challenge

Useful data points come from many places. Sometimes those places are staring you straight in the face! Take this example where the Excel Sheet name contains a date that needs to be added to data set. The data set is taken from Preppin' Data's 2019 Week Challenge if you want to try this yourself.

 


In this instance, we'd want to grab the 'Mar 2019' part of the table name to show the reporting date for the contents of the table. When inputing this data set into Prep, the table name isn't included by default. 

The Solution

A sneaky solution came to me when using actually planning another post. When Unioning files together, Prep automatically adds an additional data field called Table Names. This Table Name references which records in the data set comes from each data source. The solution to this challenge is to just add a Union step even if you are not Unioning tables of data together.


With the additional field of data containing the file name and sheet name, there is plenty of options of creating data that could be useful for you. In this case, we need to just take the end of the worksheet name. If you haven't had much experience working with string data to extract the part of the name that you want, maybe have a read through this post that will introduce you to some of the basics of working with fields containing string data types. I've used a right function to return the last eight characters in the name. 



Here's what is returned by Prep Builder:

To convert the string to be a date and making it possible to use Tableau's excellent date functions, you can convert the data type of the field by clicking on the 'Abc' in the top left of the data field and changing the data type to Date.


Once you have taken all the parts of Table Name field that you need, you can remove the field by clicking on the Ellipsis menu (the three dots icon when hovering over the field) and selecting Remove. This results in a data field with the added date.

Popular posts from this blog

2024: Week 1 - Prep Air's Flow Card

2023: Week 1 The Data Source Bank

How to...Handle Free Text