In a previous blog post I introduced the use of expander tables in Tableau when needing to handle a single row in multiple ways. You may have heard of expander tables before under the more generalised term of “scaffolding”.
In this blog post I’m going to cover some different use cases for expander tables. If you didn’t read part 1 yet, go ahead and have a skim through that…
Right let’s get into some use cases! For each case I’m going to describe the approach and benefits, as well as providing an example form the Tableau Community Forums or Tableau Public, that you can dig into in more detail.
1. To count a single row on multiple dates without using a UNION
I covered this use case in part 1 so pop back there for the detail. To recap: with an expander table you can turn a single row with an opened and closed date, into two rows. To do this you relate your existing table onto another table which has two rows, with relationship calcs of 1=1. This means every original row joins to both of the additional rows (as 1=1 is always true for the join). Then you can have a calculation that says “for copy 1 use opened date, and for copy 2 use closed date”. This allows you to count the row on both the opened date (as a +1) and the closed date (as a -1, say).
If you have more than two dates then add extra rows to the expander table (one expander row per date), and extra clauses to your calculations.
Benefits: with a UNION your data set is always duplicated meaning that you have to cater for that in other parts of your workbook that use the data (i.e. deduplicate it). With a relationship to an expander table your data will only be duplicated when you need it to be.
Example: here is the example from my VizIt Sydney presentation published to Tableau Public. The third view is the expander table version. The first view demonstrates why we need to duplicate the data, and the second view is a more traditional UNION-based solution.
2. To avoid issues from pivoting your data
Sometimes your data will look a little like this, where a measure is split out by a category or dimension:
In this case we don’t have an overall “sales” figure with a dimension for “region”. Instead we have sales for the East region in one column, and sales for the West region in another. Another example that often arises is where each year’s value is in a separate column (Sales 2023, Sales 2024, Sales 2025, etc). Unfortunately Tableau much prefers the measure to be in a single column, and there to be a row per category.
To get around this we can use the built in pivot option when building the data source:
And that will give us two new columns: Pivot Field Names (with our category), and Pivot Field Values (the measure). NB: Usually you would rename these, in this case to Region and Sales. And you would usually remove the word “Sales” prefixing the Region, I won’t do that in this example.
One problem you’ll spot above is that we have now duplicated Stock On Hand!
So whilst we can use Pivot Field Names (on Colour) and Pivot Field Values (on Columns) to create a stacked bar chart breaking Sales down by region. If we also want to show Stock On Hand, it is now double counted:
Instead we can use an expander table.
The table has a row per Region:
We need to relate that table to the original data set, with a relationship of 1=1. To do this we pick relationship calculation from each of the drop downs and enter in 1:
We can now drag Region onto Colour. Then we need a calculation for Sales which says “when the Region is East use Sales East, and when the Region is West use Sales West”, and we drag that onto Columns:
We still get our stacked bar chart of sales broken down by region. But now if we drag Stock on Hand onto the view it doesn’t double count as Tableau doesn’t need to use the expander table for that part of the view.
Benefits: similarly to avoiding a UNION, avoiding a PIVOT in favour of an expander tables means that additional data isn’t always duplicated. It is only duplicated when we need it to be. And that can help avoid having to deduplicate other values in your visualisation.
Example: Forum example.
3. Instead of Measure Names and Measure Values
In the example above you may have been thinking “I could just use the special Measure Names and Measure Values pills instead of a pivot or an expander table”. And you would be right:
With this approach the Stock On Hand isn’t double counted either. Nice!
But … yep, there was always going to be a but … the special Measure Names and Measure Values pills do have some restrictions. You can’t use them in calculations, they are harder to pass through dashboard actions, and you are restricted on sort options which can be a pain.
Using an expander table as shown in the previous section can give you your own “measure” and “value” columns, but in a way that you can use in calculations, actions and sorting. The example linked below goes into more detail.
Benefits: the special Measure Names and Measure Values pills are very handy but do have some restrictions. Those restrictions don’t apply to the normal pills you can get via use of an expander table.
Example: Forum example (scroll down further than the “best” answer, as an early post goes into the expander table option in more detail).
Further use cases
In the final blog post in the series I’ll cover the use of expander tables to:
- Create custom sub totals or grand totals
- Count a category or date in multiple groupings
- Densify your data in other ways
Until then, thanks for reading!