Using Sample – Superstore dataset (the default dataset that comes with Tableau)

What is a Calculated Field?

A calculated field is a new field you create using formulas (similar to Excel formulas) inside Tableau. It allows you to transform, combine, or analyze your data without changing the original source.

How to Create a Calculated Field

  1. In Tableau → Analysis menu → Create Calculated Field… (or right-click in the Data pane → Create Calculated Field)
  2. Give it a name
  3. Write the formula
  4. Click OK

Let’s start with very basic but extremely useful calculations using the Sample – Superstore dataset.

Chapter 1 Examples (All tested on Sample – Superstore)

1. Profit Margin (%)

One of the most common calculations.

Name: Profit Margin (%)
Formula:
[Profit] / [Sales] 

To show as percentage:
Right-click the field → Default Properties → Number Format → Percentage (1 decimal)

Use case: Drag to Color or Label to see which Sub-Categories or Regions are most profitable.

2. Total Cost (COGS)

Superstore doesn’t have Cost of Goods Sold directly, but we can calculate it.

Name: Total Cost
Formula:
[Sales] - [Profit]

Now you have Cost → useful for gross margin analysis.

3. Sales per Order

Average ticket size.

Name: Sales per Order
Formula:
SUM([Sales]) / COUNTD([Order ID])

Use AGGREGATION! This is important.
Use this as a measure (it will show correct values when you put Year or Category on view).

4. Profit per Unit

How much profit we make per item sold.

Name: Profit per Unit
Formula:
[Profit] / [Quantity]

5. Discount Amount (in $)

Discount is given as percentage, but sometimes you want the actual dollar amount.

Name: Discount Amount ($)
Formula:
[Sales] * [Discount]

6. Sales After Discount (Net Sales)

Actual revenue after applying discount.

Name: Net Sales
Formula:
[Sales] * (1 - [Discount])

7. Year over Year Sales Growth (%)

Very popular KPI.

Name: YoY Sales Growth (%)
Formula:
(ZN(SUM([Sales]) - LOOKUP(SUM([Sales]), -1))) / ZN(LOOKUP(SUM([Sales]), -1))

Explanation:

  • LOOKUP looks at previous row (when Order Date is on the view in continuous months/quartes/years)
  • ZN() replaces NULL with 0 (for the first period which has no previous)

How to use: Put Order Date (continuous) on Columns → Sales on Rows → Drag YoY Sales Growth to view.

8. Running Total Sales

Cumulative sales over time.

Name: Running Total Sales
Formula:
RUNNING_SUM(SUM([Sales]))

Step-by-Step: How to Show Running Total Sales in a Table View

(Using Sample – Superstore)

  1. Start a new sheet
  2. Drag “Order Date” to Rows
    → Right-click → Exact Date or Discrete Month/Quarter/Year (start with Discrete Year for simplicity)
    → Later we’ll switch to Continuous Month for smooth running total
  3. Drag “Sales” to Text (or Rows)
    → It will automatically become SUM(Sales)
  4. Create the calculated field exactly like this: Name: Running Total Sales
    Formula:
   RUNNING_SUM(SUM([Sales]))
  1. Drag your new “Running Total Sales” field to Text (next to or instead of regular Sales)
  2. Very important – Set the Table Calculation correctly:
    Right-click the “Running Total Sales” pill in the view → Compute Using → Table (Down)
    (or → Order Date)
    This tells Tableau to accumulate down the years/months.

Clean Table View Example (with Years)

YearSalesRunning Total Sales
2018$725,000$725,000
2019$730,000$1,455,000
2020$740,000$2,195,000
2021$1,050,000$3,245,000

Bonus: Make It Monthly (Most Common & Beautiful)

  1. Remove Year, drag Order Date as Continuous Month (green pill) to Columns
  2. Remove regular Sales from view
  3. Keep only Running Total Sales on Rows
  4. Change mark type to Line or Area → You instantly get a beautiful cumulative sales curve!

Quick Checklist So It Works 100%

  • Order Date must be in the view (Rows or Columns)
  • The field must be RUNNING_SUM(SUM([Sales])) → never just RUNNING_SUM([Sales])
  • Compute Using must be set to Order Date or Table (Down) / Pane (Down)

9. Rank of Sub-Categories by Sales

Top 10 / Bottom 10 performers.

Name: Sales Rank
Formula:
RANK(SUM([Sales]))

or for unique rank (handles ties differently):

RANK_UNIQUE(SUM([Sales]))

Tip: Right-click the pill → Compute Using → Sub-Category

10. Simple Profit Indicator (Good/Bad)

Color-code profit positive/negative.

Name: Profit Status
Formula:
IF [Profit] > 0 THEN "Profitable" 
ELSE "Loss" 
END

Now drag this to Color shelf → instantly see red/blue profitable/loss-making segments.

Chapter 1 – Quick Practice Dashboard Idea

Build this in 5 minutes:

  1. Sheet 1: Sales by Sub-Category (bar chart) → Color by Profit Status
  2. Sheet 2: Profit Margin (%) by Region (map or bar)
  3. Sheet 3: Running Total Sales over time (area chart)
  4. Sheet 4: Top 10 Sub-Categories by Sales (use Sales Rank filter 1 to 10)

What You Learned in Chapter 1

  • How to create calculated fields
  • Basic arithmetic: +, -, *, /
  • Common business calculations (margin, net sales, discount amount)
  • First table calculations: LOOKUP, RUNNING_SUM, RANK
  • Using ZN() to handle nulls
  • IF statements (basic logic)

In Chapter 2 will cover: Logical Functions, Date Functions, String Functions & Parameters.

Using Sample – Superstore dataset (the default dataset that comes with Tableau)

What is a Calculated Field?

A calculated field is a new field you create using formulas (similar to Excel formulas) inside Tableau. It allows you to transform, combine, or analyze your data without changing the original source.

How to Create a Calculated Field

  1. In Tableau → Analysis menu → Create Calculated Field… (or right-click in the Data pane → Create Calculated Field)
  2. Give it a name
  3. Write the formula
  4. Click OK

Let’s start with very basic but extremely useful calculations using the Sample – Superstore dataset.

Chapter 1 Examples (All tested on Sample – Superstore)

1. Profit Margin (%)

One of the most common calculations.

Name: Profit Margin (%)
Formula:
[Profit] / [Sales] 

To show as percentage:
Right-click the field → Default Properties → Number Format → Percentage (1 decimal)

Use case: Drag to Color or Label to see which Sub-Categories or Regions are most profitable.

2. Total Cost (COGS)

Superstore doesn’t have Cost of Goods Sold directly, but we can calculate it.

Name: Total Cost
Formula:
[Sales] - [Profit]

Now you have Cost → useful for gross margin analysis.

3. Sales per Order

Average ticket size.

Name: Sales per Order
Formula:
SUM([Sales]) / COUNTD([Order ID])

Use AGGREGATION! This is important.
Use this as a measure (it will show correct values when you put Year or Category on view).

4. Profit per Unit

How much profit we make per item sold.

Name: Profit per Unit
Formula:
[Profit] / [Quantity]

5. Discount Amount (in $)

Discount is given as percentage, but sometimes you want the actual dollar amount.

Name: Discount Amount ($)
Formula:
[Sales] * [Discount]

6. Sales After Discount (Net Sales)

Actual revenue after applying discount.

Name: Net Sales
Formula:
[Sales] * (1 - [Discount])

7. Year over Year Sales Growth (%)

Very popular KPI.

Name: YoY Sales Growth (%)
Formula:
(ZN(SUM([Sales]) - LOOKUP(SUM([Sales]), -1))) / ZN(LOOKUP(SUM([Sales]), -1))

Explanation:

  • LOOKUP looks at previous row (when Order Date is on the view in continuous months/quartes/years)
  • ZN() replaces NULL with 0 (for the first period which has no previous)

How to use: Put Order Date (continuous) on Columns → Sales on Rows → Drag YoY Sales Growth to view.

8. Running Total Sales

Cumulative sales over time.

Name: Running Total Sales
Formula:
RUNNING_SUM(SUM([Sales]))

Step-by-Step: How to Show Running Total Sales in a Table View

(Using Sample – Superstore)

  1. Start a new sheet
  2. Drag “Order Date” to Rows
    → Right-click → Exact Date or Discrete Month/Quarter/Year (start with Discrete Year for simplicity)
    → Later we’ll switch to Continuous Month for smooth running total
  3. Drag “Sales” to Text (or Rows)
    → It will automatically become SUM(Sales)
  4. Create the calculated field exactly like this: Name: Running Total Sales
    Formula:
   RUNNING_SUM(SUM([Sales]))
  1. Drag your new “Running Total Sales” field to Text (next to or instead of regular Sales)
  2. Very important – Set the Table Calculation correctly:
    Right-click the “Running Total Sales” pill in the view → Compute Using → Table (Down)
    (or → Order Date)
    This tells Tableau to accumulate down the years/months.

Clean Table View Example (with Years)

YearSalesRunning Total Sales
2018$725,000$725,000
2019$730,000$1,455,000
2020$740,000$2,195,000
2021$1,050,000$3,245,000

Bonus: Make It Monthly (Most Common & Beautiful)

  1. Remove Year, drag Order Date as Continuous Month (green pill) to Columns
  2. Remove regular Sales from view
  3. Keep only Running Total Sales on Rows
  4. Change mark type to Line or Area → You instantly get a beautiful cumulative sales curve!

Quick Checklist So It Works 100%

  • Order Date must be in the view (Rows or Columns)
  • The field must be RUNNING_SUM(SUM([Sales])) → never just RUNNING_SUM([Sales])
  • Compute Using must be set to Order Date or Table (Down) / Pane (Down)

9. Rank of Sub-Categories by Sales

Top 10 / Bottom 10 performers.

Name: Sales Rank
Formula:
RANK(SUM([Sales]))

or for unique rank (handles ties differently):

RANK_UNIQUE(SUM([Sales]))

Tip: Right-click the pill → Compute Using → Sub-Category

10. Simple Profit Indicator (Good/Bad)

Color-code profit positive/negative.

Name: Profit Status
Formula:
IF [Profit] > 0 THEN "Profitable" 
ELSE "Loss" 
END

Now drag this to Color shelf → instantly see red/blue profitable/loss-making segments.

Chapter 1 – Quick Practice Dashboard Idea

Build this in 5 minutes:

  1. Sheet 1: Sales by Sub-Category (bar chart) → Color by Profit Status
  2. Sheet 2: Profit Margin (%) by Region (map or bar)
  3. Sheet 3: Running Total Sales over time (area chart)
  4. Sheet 4: Top 10 Sub-Categories by Sales (use Sales Rank filter 1 to 10)

What You Learned in Chapter 1

  • How to create calculated fields
  • Basic arithmetic: +, -, *, /
  • Common business calculations (margin, net sales, discount amount)
  • First table calculations: LOOKUP, RUNNING_SUM, RANK
  • Using ZN() to handle nulls
  • IF statements (basic logic)

In Chapter 2 will cover: Logical Functions, Date Functions, String Functions & Parameters.