We are Still using Sample – Superstore dataset
2.1 Logical Functions (IF, IIF, CASE)
| # | Name | Formula | Purpose / Example Use |
|---|---|---|---|
| 1 | Profit Status Detailed | IF [Profit] > 0 THEN "Profitable" ELSEIF [Profit] < 0 THEN "Loss" ELSE "Break-even" END | Better than simple Good/Bad |
| 2 | High Discount Flag | IF [Discount] >= 0.3 THEN "High Discount" ELSE "Normal" END | Flag products sold with 30%+ discount |
| 3 | Priority Customer | IF [Sales] > 5000 THEN "VIP" ELSEIF [Sales] > 2000 THEN "Gold" ELSE "Standard" END | Customer tiering by order value |
| 4 | IIF (shortcut version) | IIF([Profit Ratio] > 0.15, "Excellent", "Normal") | Faster to write when only 2 outcomes |
| 5 | CASE (cleaner for many options) | CASE [Region] WHEN "Central" THEN "North America" WHEN "East" THEN "North America" WHEN "South" THEN "North America" ELSE "West" END | Group regions into bigger areas |
Detailed Explanation of Examples Given Above:
1. Profit Status Detailed
Formula: IF [Profit] > 0 THEN “Profitable” ELSEIF [Profit] < 0 THEN “Loss” ELSE “Break-even” END
This calculated field creates a more nuanced text category for profitability instead of just positive/negative. It evaluates each row’s [Profit] value:
- If profit is greater than zero → “Profitable”
- If profit is less than zero → “Loss”
- If exactly zero → “Break-even”
Why it’s useful in Sample – Superstore: Many segments (especially Technology) are highly profitable, while others (like Tables in Furniture) often lose money. This field lets you quickly color-code a bar chart of Sales by Sub-Category and instantly spot the three states. It’s especially helpful in dashboards where stakeholders want to see not just red/green but also the rare break-even cases. You can drag this field to Color or Label for clear visual segmentation. (98 words)
2. High Discount Flag
Formula: IF [Discount] >= 0.3 THEN “High Discount” ELSE “Normal” END
This simple IF statement flags any row where the discount is 30% or higher as “High Discount”; everything else is “Normal”.
Why it’s useful in Sample – Superstore: Superstore data shows heavy discounting in certain regions (Central) and sub-categories (Bookcases, Tables) often correlates with negative profit. By creating this flag, you can filter views to only high-discount transactions, compare average profit between “High Discount” and “Normal”, or color marks to highlight potentially dangerous discounting behavior. A common insight: many loss-making orders have “High Discount”. Use this on Detail or Color to reveal patterns that drive profitability issues. (92 words)
3. Priority Customer
Formula: IF [Sales] > 5000 THEN “VIP” ELSEIF [Sales] > 2000 THEN “Gold” ELSE “Standard” END
This nested IF tiers customers (or actually orders, since it’s row-level) based on the Sales amount of that specific order:
- Over $5,000 → “VIP”
- $2,001–$5,000 → “Gold”
- $2,000 or less → “Standard”
Why it’s useful in Sample – Superstore: Although the calculation is at the order level, when you aggregate (e.g., SUM([Sales]) by Customer Name), you can analyze customer value distribution. Create a view of Customer Name → SUM(Sales) colored by the most common tier, or count distinct orders per tier. It helps identify how many high-value orders exist and which customers consistently place large orders. Great for customer segmentation dashboards and targeting marketing efforts. (96 words)
4. IIF (shortcut version)
Formula: IIF([Profit Ratio] > 0.15, “Excellent”, “Normal”)
IIF is a shorthand for simple two-outcome IF statements. Here it checks if Profit Ratio (you need to create [Profit]/[Sales] first) exceeds 15%. If yes → “Excellent”, otherwise → “Normal”. You can add an optional third argument for ELSE (e.g., “Poor”).
Why it’s useful in Sample – Superstore: When you only need two categories, IIF is faster to write and slightly better performing than full IF-THEN-ELSEIF-END. Use it to quickly highlight sub-categories or regions with exceptional margins. For example, Phones and Copiers often exceed 15% margin while Tables and Bookcases rarely do. Drag to Color for instant visual distinction in profitability dashboards. It’s perfect for quick binary classifications. (94 words)
5. CASE (cleaner for many options)
Formula: CASE [Region] WHEN “Central” THEN “North America” WHEN “East” THEN “North America” WHEN “South” THEN “North America” ELSE “West” END
CASE is ideal when testing the same field against multiple values. Here it groups three regions (Central, East, South) into “North America” and leaves West as “West” (note: Superstore only has four US regions).
Why it’s useful in Sample – Superstore: CASE statements are more readable than long nested IFs when you have many conditions on one dimension. This example demonstrates regional grouping for higher-level analysis (e.g., comparing broader areas). You could extend it to map “West” → “North America” too if desired. Use the resulting field instead of raw [Region] in views to simplify dashboards for executives who want a bigger-picture view rather than four separate regions. CASE is generally preferred over chains of ELSEIF for equality checks.
2.2 Date Functions – Super Useful on Superstore!
| # | Name | Formula | What it shows in Superstore |
|---|---|---|---|
| 6 | Year of Order | YEAR([Order Date]) | 2018, 2019, 2020, 2021 |
| 7 | Month Name | DATENAME('month', [Order Date]) | January, February… |
| 8 | Quarter Number | DATEPART('quarter', [Order Date]) | 1, 2, 3, 4 |
| 9 | Is Cyber Monday? | [Order Date] = #2018-11-26# OR [Order Date] = #2019-11-25# OR [Order Date] = #2020-11-30# OR [Order Date] = #2021-11-29# | Boolean TRUE/FALSE |
| 10 | Days to Ship (Actual) | DATEDIFF('day', [Order Date], [Ship Date]) | How many days it actually took |
| 11 | Shipping Delay | IF [Ship Mode] = "Same Day" AND [Days to Ship] > 0 THEN "Delayed" ELSEIF [Ship Mode] = "First Class" AND [Days to Ship] > 1 THEN "Delayed" ELSE "On Time" END | Performance of shipping mode |
| 12 | Current Year Sales | IF YEAR([Order Date]) = YEAR(TODAY()) THEN [Sales] END | Only 2021 sales (useful in running dashboards) |
2.3 String Functions – Clean & Combine Text
| # | Name | Formula | Example Output |
|---|---|---|---|
| 13 | Customer – City | [Customer Name] + " - " + [City] | “Claire Gute – Henderson” |
| 14 | Product Full Name | TRIM([Category] + " - " + [Sub-Category] + " (" + [Product Name] + ")") | “Technology – Phones (Samsung Convoy)” |
| 15 | First 3 Letters of Sub-Cat | LEFT([Sub-Category], 3) | “Boo” from “Bookcases”, “Tab” from “Tables” |
| 16 | Contains “Chair” | CONTAINS([Product Name], "Chair") | TRUE / FALSE |
| 17 | Clean Phone (remove dashes) | REPLACE([Phone Number], "-", "") | Turns 541-754-3010 → 5417543010 |
2.4 Parameters – Make Your Calculations Dynamic!
Parameters in Tableau are dynamic, user-controlled values that you create to make your visualizations and calculations interactive and flexible — without altering the underlying data.
Think of a parameter as a customizable “knob” or input box that appears on your dashboard, allowing you (or any viewer) to change a single value on the fly. This value can then be referenced inside calculated fields, filters, reference lines, or even titles, instantly updating the entire view based on the user’s selection.
Unlike regular fields from your data source, parameters are not tied to any row or column in your dataset. They are standalone values you define manually, such as a number, string, date, or list of options.
Key characteristics of parameters:
- Fully controlled by the user via a dropdown, slider, or type-in control shown on the dashboard.
- Can be integer, float, string, boolean, date, or datetime.
- Support single value or list of allowable values (e.g., dropdown menu).
- Extremely useful for “what-if” analysis, scenario modeling, and personalized dashboards.
Common use cases in Sample – Superstore:
- Dynamic thresholds: Create a “Profit Threshold” parameter (e.g., 0 to 50%) and use it in a calculated field to highlight sub-categories exceeding that margin. Change the parameter → colors instantly update.
- Top N analysis: A “Top N” integer parameter lets users switch between Top 5, 10, or 20 products by sales.
- Scenario testing: A “Growth Rate” parameter to simulate future sales projections.
- Flexible filtering: A string parameter with product categories to filter the view dynamically.
How they work with calculated fields: You reference a parameter in a formula using its exact name in square brackets, e.g., [Profit Threshold]. When the parameter value changes, any calculation or filter using it recalculates automatically.
Benefits:
- Empower end-users to explore data their way.
- Reduce the need for multiple similar dashboards.
- Enable powerful sensitivity and scenario analysis.
In short, parameters transform static reports into interactive, user-driven experiences — one of the most powerful features for delivering insightful, adaptable dashboards in Tableau.
Let’s create your first parameter and use it in calculations.
Step 1: Create Parameter – Profit Threshold
- Right-click in Data pane → Create Parameter
- Name: Profit Threshold
- Data type: Float
- Allowable values: Range 0 to 0.5, step 0.01
- Current value: 0.10
- Click OK
Now create these calculated fields that use this parameter:
| # | Name | Formula | What it does |
|---|---|---|---|
| 18 | Target Profit Margin | [Profit] / [Sales] >= [Profit Threshold] | TRUE if current margin ≥ parameter value |
| 19 | Bonus Calculation | IF [Target Profit Margin] THEN [Sales] * 0.02 ELSE 0 END | Gives 2% bonus on sales when margin target is met |
| 20 | Dynamic Top N Sub-Categories | RANK(SUM([Sales])) <= [Top N Parameter] | (We’ll create Top N Parameter in next chapter) |
Chapter 2 Mini Dashboard Challenge (10–15 min)
Build this dashboard using only Chapter 1 + Chapter 2 calculations:
- Bar chart: Sales by Sub-Category, color by Profit Status Detailed
- Highlight table: Region × Category, text = Profit Margin, background color = Target Profit Margin (green if true)
- Line chart: Monthly Sales + Running Total Sales
- Add the Profit Threshold parameter control on the dashboard → watch colors change live!
You now know enough now to impress anyone with clean, dynamic analysis on the Superstore data.
Ready for the next level?
In “Chapter 3” and we’ll dive into:
- Level of Detail (LOD) Expressions {FIXED, INCLUDE, EXCLUDE}
- Advanced Table Calculations
- Sets, Bins
- Top N + Other + Index tricks
