Chapter 17. Unioning

Most software that works with data demands that you form a single table of data to work from. However, the world is often not that simple, so you’ll often have to pull together many tables of data to build that single table. Unioning is a data preparation technique that will help you with this task.

What Is a Union?

You can think of unioning as stacking one data set on top of another. Columns that contain the same content should be unioned as part of the data preparation process. As you’ll soon see, this requires the data structures to be very similar.

Let’s look at two separate example data sets: York Store Sales (Figure 17-1) and Leeds Store Sales (Figure 17-2).

York Store Sales data set
Figure 17-1. York Store Sales data set
Leeds Store Sales data set
Figure 17-2. Leeds Store Sales data set

Unioning these two tables removes the extra set of column headers and stacks the rows of data on top of each other (Figure 17-3).

Unioned result of York and Leeds data sets
Figure 17-3. Unioned result of York and Leeds data sets

The union is usually determined by whether the data fields are:

  • Named the same in each data set. The contents of columns with the same name will be stacked in rows under that column name in the resulting data set. Currently, Prep Builder ...

Get Tableau Prep: Up & Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.