Bird
Raised Fist0
Tableaubi_tool~10 mins

Difference and percent difference in Tableau - Cell-by-Cell Formula Trace

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Sample Data

Monthly sales data for four months

CellValue
A1Month
B1Sales
A2Jan
B21000
A3Feb
B31200
A4Mar
B4900
A5Apr
B51500
Formula Trace
Difference = SUM([Sales]) - LOOKUP(SUM([Sales]), -1) Percent Difference = (Difference) / LOOKUP(SUM([Sales]), -1)
Step 1: SUM([Sales]) at Feb = 1200
Step 2: LOOKUP(SUM([Sales]), -1) at Feb = SUM([Sales]) at Jan = 1000
Step 3: Difference at Feb = 1200 - 1000
Step 4: Percent Difference at Feb = 200 / 1000
Step 5: SUM([Sales]) at Mar = 900
Step 6: LOOKUP(SUM([Sales]), -1) at Mar = SUM([Sales]) at Feb = 1200
Step 7: Difference at Mar = 900 - 1200
Step 8: Percent Difference at Mar = -300 / 1200
Step 9: SUM([Sales]) at Apr = 1500
Step 10: LOOKUP(SUM([Sales]), -1) at Apr = SUM([Sales]) at Mar = 900
Step 11: Difference at Apr = 1500 - 900
Step 12: Percent Difference at Apr = 600 / 900
Cell Reference Map
     A       B
  +-------+-------+
1 | Month | Sales |
  +-------+-------+
2 | Jan   | 1000  |
  +-------+-------+
3 | Feb   | 1200  | <-- Uses B3 and LOOKUP to B2
  +-------+-------+
4 | Mar   | 900   | <-- Uses B4 and LOOKUP to B3
  +-------+-------+
5 | Apr   | 1500  | <-- Uses B5 and LOOKUP to B4
  +-------+-------+
The formula uses current month sales (column B) and previous month sales via LOOKUP function to calculate difference and percent difference.
Result
     A       B       C           D
  +-------+-------+-----------+--------------+
1 | Month | Sales | Difference| Percent Diff |
  +-------+-------+-----------+--------------+
2 | Jan   | 1000  |           |              |
  +-------+-------+-----------+--------------+
3 | Feb   | 1200  | 200       | 0.20         |
  +-------+-------+-----------+--------------+
4 | Mar   | 900   | -300      | -0.25        |
  +-------+-------+-----------+--------------+
5 | Apr   | 1500  | 600       | 0.6667       |
  +-------+-------+-----------+--------------+
The Difference column shows the change in sales from the previous month. The Percent Diff column shows that change as a decimal fraction of the previous month's sales.
Sheet Trace Quiz - 3 Questions
Test your understanding
What is the Difference value for March?
A300
B-300
C2100
D900
Key Result
Difference = Current value minus previous value; Percent Difference = Difference divided by previous value

Practice

(1/5)
1. What does the Difference calculation in Tableau typically show?
easy
A. The total sum of all values
B. The average value over time
C. How much a value changed between two points
D. The maximum value in a dataset

Solution

  1. Step 1: Understand the meaning of Difference

    Difference measures the change in value from one point to another, showing increase or decrease.
  2. Step 2: Compare with other options

    Sum, average, and maximum describe different calculations unrelated to change between points.
  3. Final Answer:

    How much a value changed between two points -> Option C
  4. Quick Check:

    Difference = Change amount [OK]
Hint: Difference = New value minus old value [OK]
Common Mistakes:
  • Confusing difference with total sum
  • Thinking difference shows average
  • Mixing difference with maximum value
2. Which of the following Tableau calculations correctly computes the percent difference between the current and previous value?
easy
A. ([Current Value] - [Previous Value]) / [Previous Value]
B. ([Previous Value] - [Current Value]) / [Current Value]
C. [Current Value] + [Previous Value] / [Previous Value]
D. [Current Value] * [Previous Value]

Solution

  1. Step 1: Recall percent difference formula

    Percent difference = (New - Old) / Old, showing change relative to original.
  2. Step 2: Match formula to options

    ([Current Value] - [Previous Value]) / [Previous Value] matches formula exactly; others either reverse or misuse operations.
  3. Final Answer:

    ([Current Value] - [Previous Value]) / [Previous Value] -> Option A
  4. Quick Check:

    Percent difference = (New - Old) / Old [OK]
Hint: Percent difference = difference divided by previous value [OK]
Common Mistakes:
  • Swapping numerator terms
  • Dividing by current value instead of previous
  • Using addition or multiplication instead of division
3. Given this Tableau calculated field:
LOOKUP(SUM([Sales]), 0) - LOOKUP(SUM([Sales]), -1)
What does this calculation return?
medium
A. The percent difference in sales between current and previous row
B. The total sales for all rows
C. The sum of sales for the previous row only
D. The difference in sales between the current and previous row

Solution

  1. Step 1: Understand LOOKUP function usage

    LOOKUP(SUM([Sales]), 0) returns current row sales; LOOKUP(SUM([Sales]), -1) returns previous row sales.
  2. Step 2: Calculate difference

    Subtracting previous from current gives the difference in sales between rows.
  3. Final Answer:

    The difference in sales between the current and previous row -> Option D
  4. Quick Check:

    LOOKUP difference = sales change [OK]
Hint: LOOKUP with offset -1 gets previous row value [OK]
Common Mistakes:
  • Thinking it calculates percent difference
  • Assuming it sums all sales
  • Confusing current and previous row values
4. You wrote this Tableau formula to calculate percent difference:
(SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / SUM([Sales])
But the results seem incorrect. What is the likely error?
medium
A. Not using WINDOW_SUM instead of SUM
B. Dividing by current sales instead of previous sales
C. Subtracting current sales from previous sales
D. Using LOOKUP with offset -1 incorrectly

Solution

  1. Step 1: Analyze denominator in formula

    The formula divides by SUM([Sales]) which is current sales, but percent difference should divide by previous sales.
  2. Step 2: Identify correct denominator

    Correct formula divides by LOOKUP(SUM([Sales]), -1) to get previous sales as denominator.
  3. Final Answer:

    Dividing by current sales instead of previous sales -> Option B
  4. Quick Check:

    Percent difference denominator = previous value [OK]
Hint: Divide by previous value, not current, for percent difference [OK]
Common Mistakes:
  • Using current value as denominator
  • Confusing subtraction order
  • Misusing LOOKUP offset
5. You want to create a Tableau dashboard showing monthly sales percent difference compared to the previous month. Which approach correctly calculates this and handles months with zero sales without errors?
hard
A. Use (SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / NULLIF(LOOKUP(SUM([Sales]), -1), 0) to avoid division by zero
B. Use (SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / SUM([Sales]) ignoring zero sales
C. Use SUM([Sales]) / LOOKUP(SUM([Sales]), -1) without subtraction
D. Use WINDOW_SUM(SUM([Sales])) - WINDOW_SUM(SUM([Sales])) for difference

Solution

  1. Step 1: Calculate percent difference with zero check

    Percent difference = (Current - Previous) / Previous; use NULLIF to avoid division by zero errors when previous sales are zero.
  2. Step 2: Evaluate options for correctness

    Use (SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / NULLIF(LOOKUP(SUM([Sales]), -1), 0) to avoid division by zero uses NULLIF to prevent errors; others either divide by current or ignore zero sales causing errors or wrong results.
  3. Final Answer:

    Use (SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / NULLIF(LOOKUP(SUM([Sales]), -1), 0) to avoid division by zero -> Option A
  4. Quick Check:

    Use NULLIF to handle zero denominator [OK]
Hint: Use NULLIF to prevent division by zero in percent difference [OK]
Common Mistakes:
  • Dividing by current sales instead of previous
  • Ignoring zero sales causing errors
  • Using sum differences without percent calculation