Quantcast
Channel: InterWorks
Viewing all articles
Browse latest Browse all 2698

Questions from Tableau Training: Union File Names as Years

$
0
0
Change Data Type to Date

There is an example we do in the Tableau Desktop Intermediate course to look at how to union your data. In the example, we use Tableau’s Union function to append different sheets, labeled as different quarters, from a single Excel file into one long table in Tableau. My quick-thinking class the other week immediately wanted to know the limits of Tableau’s ability here. Rodney asked:

“Can we union separate files as the year here?”

Great question, Rodney – especially for a team within a company where there maybe exists a shared folder that uses standardized naming conventions for their files (e.g. Sales 2018). So, I created just a short test of Tableau’s abilities here, with three Excel files labeled as “sales eg (year)” and containing four quarters of data. I also put them in different nested folders so we can make use of Tableau’s Wildcard Union ability.

Three Excel Files

The TL;DR Version in Tableau

  1. Set up Wildcard Union – file names must follow a naming convention
  2. File paths will come in as a new column
  3. Use custom splits and/or calculated fields to narrow the file path field down to the year, e.g. “2018”
  4. Use a calculated field to combine date parts, e.g. [Q]+“ ”+[Yr]
  5. Change the data type to Date
  6. Change the start of your fiscal year from the Default Properties of the pill in the Data pane

 

The Extended Version

To get started, we connect to the first file and set up the union like we would normally. We are looking for files with the stem “sales eg,” with differences occurring in the name after that:

Wildcard Union in Tableau

When we run the Wildcard Union, a new field appears, containing the entire file path:

New Field After Union

So, our steps to complete now are:

  1. Isolate the year from the file path field, and …
  2. Combine with the sheet field to give us a more-complete date field to use.

 

We can do this using custom splits, calculated fields or a combination of the two. The basic functions we will use here for calculated fields are RIGHT and LEFT. Here, I took the right-most nine characters, then the left-most four characters of those:

Year Calculated Field

A simple calculated field can join these fields together:

Calculated Field to Join Fields

Then we can change the data type to Date from the icon in the top-left of the row to get an actual date field:

Change Data Type to Date

Tableau will assign the first month of each quarter to bring the date down to the level of detail it needs: M/D/YYYY in this case. I can change the start of my fiscal year from the Default Properties of my Date field if I need different months associated with each quarter.

The post Questions from Tableau Training: Union File Names as Years appeared first on InterWorks.


Viewing all articles
Browse latest Browse all 2698

Trending Articles