In week four of DS61's training, we went deeper into Tableau. One of the things we covered was sets.

What are sets?

Sets are custom fields that define a subset of your data based on some conditions. In Tableau, they're marked with a Venn diagram icon.

There are 3 main types of sets:

  • Constant Sets: Members of the set are FIXED and do not change even when underlying data changes. They are created by manually selecting specific dimension members or marks in a view
  • Computed Sets: Members of the set are DYNAMIC and change based on rules, conditions, or top/bottom rankings when underlying data changes. They're built using the General, Condition or Top tabs. q
  • Combined Sets: You can create a set made up of two different sets, so you can compare their members. This is only possible if the two sets are based on the same field.
Menu for combining sets

Where it got interesting

An example came up in training that was intriguingx. We wanted the products that met two rules: Profit below 0 and in the top 10 by number of customers.

My first instinct was to go straight to a combined set: make one set for each rule, then combine them. As shown in the image above, you can keep all members in both sets, only the shared members, or the members of one set except the shared ones.

However, you can also put both rules in a single set, using the Condition and Top tabs together.

Summary pane

You'd think both methods give the same answer, but they don't!

Why the single set is different

In a single set, the tabs are applied in order, from left to right. So Tableau:

  1. Applies the Condition first, keeping only the loss-making products.
  2. Then applies Top, taking the 10 products with the most customers from what's left.

That makes it the top 10 loss-making products, not the top 10 products that also happen to be loss-making.

When I compared it with a plain top 10 set, only one product, the KI Adjustable-Height Table, was in both. The rest of the overall top 10 (staples, binders and so on) make a profit, so the condition removed them before the ranking happened.

In/Out comparison table

When to use what?

The same two rules can give you three different answers, depending on the question:

  • Single set (Condition + Top): "Of the products losing money, which 10 have the most customers?" Here, that's 10 products.
  • Combined set, shared members: "Which of the 10 most popular products loose money?" Here, just 1 product.
  • Combined set, all members: "Which products are either popular or losing money?" Here, that's the top 10 plus every loss-making product.

So before reaching for a combined set, check which question you're actually asking. The difference comes down to order. A single set filters first and then ranks, while a combined set builds each set separately and then compares them.