What is the LOOKUP Function in Tableau?
One of the most powerful tools in any Tableau user's kit is the LOOKUP function, especially when you need to compare values over time. It’s the key to unlocking period-over-period calculations like year-over-year growth, comparing a month's sales to the previous one, and so much more. This article will walk you through what the LOOKUP function is, how to use it, and provide step-by-step examples you can follow along with.
What is Tableau's LOOKUP Function?
The LOOKUP function is a special type of function in Tableau called a table calculation. Unlike simple calculations that work on a single row of data at a time (like SUM([Sales]) / SUM([Quantity])), table calculations operate on the entire table of data currently visible in your worksheet. This allows them to perform calculations based on the position of a value relative to others in the view.
If you're coming from a spreadsheet world, you might be tempted to think of it like VLOOKUP or INDEX/MATCH. While the goal of fetching another value is similar, the mechanism is completely different and, in many ways, much more powerful in a visualized context.
Think Relative Position, Not Specific Value
The key difference is that VLOOKUP searches for a specific matching value in another column. The LOOKUP function in Tableau doesn’t search for a value, it simply looks a certain number of rows away from the current position.
Instead of saying "find the sales for January 2023," the LOOKUP function says "from my current position, look one step backward." If your current position is February 2023, it retrieves the value for January 2023. If your current position is March 2023, it fetches the value for February 2023. This is what makes it so dynamic and perfect for visual analysis.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
The Syntax Broken Down
The syntax for the function is cleanly simple:
LOOKUP(expression, [offset])
expression: This is the value you want to return. It's almost always an aggregated measure, likeSUM([Sales])orCOUNTD([User ID]).[offset]: This tells Tableau how many rows to move from the current position. It's the "look" part of the instruction.
Why Is the LOOKUP Function So Powerful?
Once you get the hang of LOOKUP, you'll find it solves countless everyday analysis challenges. It’s your go-to function whenever a question involves comparing something to its past or future self.
Common use cases include:
- Period-over-period growth: Calculate Month-over-Month (MoM), Year-over-Year (YoY), or even Week-over-Week (WoW) change.
- Direct value comparisons: See the difference in sales between this month and last month directly in a tooltip or a column.
- Baseline comparisons: Compare every value in a series to the very first value.
- Creating running calculations: Use it as a building block for more advanced calculations like moving averages.
A Step-by-Step Guide to Using the LOOKUP Function
The best way to learn is by doing. Let's build a couple of common views using the LOOKUP function with the Sample - Superstore dataset that comes with Tableau.
Example 1: Calculating Year-over-Year (YoY) Sales Growth
This is the classic use case for LOOKUP and something almost every business needs to track.
Step 1: Build Your Base View
First, let's create a simple line chart showing sales over time.
- Drag Order Date to the Columns shelf. Make sure it's set to the discrete (blue pill) YEAR(Order Date).
- Drag Sales to the Rows shelf. By default, it will be SUM(Sales).
You should now have a simple bar chart showing total sales for each year in the dataset.
Step 2: Create a 'Previous Year Sales' Calculation
Next, we need to create a calculated field that gets the sales figures from the prior year.
- Click the down arrow in the top right of the data pane and select Create Calculated Field…
- Name the field Previous Year Sales.
- Enter the following formula:
LOOKUP(SUM([Sales]), -1)
- Click OK.
This tells Tableau: for whatever sales value is in the current position, go back one position (-1) along the table and grab that sales figure.
Step 3: Create the YoY Growth Percentage Calculation
Now that we have both the current year's sales and the previous year's sales, we can calculate the growth between them.
- Create another calculated field named YoY Growth %.
- Enter the following formula:
(SUM([Sales]) - [Previous Year Sales]) / [Previous Year Sales]
- Click OK. Format this calculated field as a Percentage to make it easier to read later. (Right-click the field in the data pane → Default Properties → Number Format… → Percentage).
Step 4: Bring it All Together in the View
Let's add our two new fields to a text table to see what's happening. Drag Previous Year Sales and YoY Growth % from the Data Pane and drop them onto the "Text" card in the Marks pane.
You'll immediately see the calculation in action. For 2022, the Previous Year Sales column shows the same value as the initial SUM(Sales) for 2021. And the YoY Growth % for 2022 shows the calculated growth between those two years.
Notice that the first year (2020) has nulls for both fields. This is correct — there's no data before 2020, so there is nothing for the LOOKUP function to find!
Example 2: Comparing a Product's Sales to the One Ranked Above It
This example shows that LOOKUP isn't just for dates. It works with any dimension, and it highlights how sorting is critical.
Step 1: Set Up the View with a Sorted Dimension
- Put Sub-Category on the Rows shelf and SUM(Sales) on the Text card.
- Sort the Sub-Categories in descending order by sales. (Click the sort icon on the Sub-Category pill or in the toolbar). "Chairs" and "Phones" should be at the top.
Step 2: Find the Previous Product's Sales
Let's create one calculated field to grab the sales of the product right above the current one in the view.
- Create a new calculated field named Previous Product Sales.
- Enter the familiar formula:
LOOKUP(SUM([Sales]), -1). - Drag this new field onto your text table.
Because the table is sorted by sales, the value for Previous Product Sales for Phones is the sales value of Chairs. The context is everything!
Step 3: Calculate the Sales Difference
We can now easily calculate the drop-off in sales from one product category to the next.
- Create a calculated field called Sales Difference.
- Use the formula:
SUM([Sales]) - ZN([Previous Product Sales]). UsingZN()is a good practice, it treats any nulls (like for the very first row) as zeros. - Drag this field to the view to see the sales difference between each row and the one above it.
Essential Tips & Common Pitfalls
Working with table calculations can sometimes feel tricky. If your view isn't showing what you expect, check these three things first.
Mastering the "Compute Using" Setting
This is the number one source of confusion. The Compute Using setting tells Tableau the direction and scope for the LOOKUP. When you drag a table calculation to the view, right-click it and look at the Compute Using options.
- Table (across): The calculation moves left-to-right along a row. This is the default and was correct for our YoY example.
- Table (down): The calculation moves top-to-bottom down a column. This was correct for our sorted products example.
- Pane (down), Pane (across): Works similarly, but restarts for every pane in your visualization. This is useful when you have multiple levels of detail.
- Specific Dimensions: You can explicitly tell Tableau which dimensions define the partition (when calculations restart) and which define the addressing (the direction of the calculation).
A good rule of thumb is to ask yourself, "In which direction should Tableau walk through my data to find the 'previous' value?"
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Dealing with the Inevitable Nulls
As we saw, the first row or column will always be null because there's nothing for LOOKUP to reference. You can handle this in a few ways:
- Leave it as is: Often, this is the most accurate representation.
- Use the ZN() function: Wrap your LOOKUP in ZN(), like
ZN(LOOKUP(SUM([Sales]),-1)). This turns the null into a 0. It's useful mathematically but be careful it doesn't skew your results visually (e.g., creating a big dip in a line chart). - Filter them out: In some cases, you may want to hide the row with the null. You can do this by dragging your calculated field to the Filter shelf and excluding Null values.
Sort Order Defines Everything
The LOOKUP function computes after filters and sorting have been applied to the worksheet. This means the sort order critically defines what "previous" and "next" even mean. If you change the sort in our sub-category example from descending sales to alphabetical, the Previous Product Sales values would change completely because the row order changed.
Always double-check your sort settings before you trust the output of a LOOKUP function based on a non-time-based dimension.
Final Thoughts
The LOOKUP function is an indispensable part of your Tableau toolkit for any kind of comparative analysis, especially period-over-period tracking. By understanding that it works based on relative position and by paying close attention to your "Compute Using" and sorting settings, you can reliably perform calculations that would be impossibly manual in a simple spreadsheet.
We know that even with great tools like Tableau, building reports from the ground up can take time away from actual analysis. That's why we created a tool to automate this process. At Graphed, instead of writing LOOKUP functions by hand and configuring table calculations, you can just ask a question like, "Show me month-over-month revenue growth from Stripe" or "Compare customer acquisition costs by channel for the past 90 days." Our AI handles the connections, calculations, and visualizations, turning your real-world questions into live dashboards instantly. If you want to skip straight to the insights, you can try Graphed for yourself.
Related Articles
Facebook Ads for Restaurants: The Complete 2026 Strategy Guide
Learn how to run profitable Facebook ads for restaurants in 2026. This comprehensive guide covers the 7 killer strategies, ad formats, targeting, and budgeting that top restaurants use to drive reservations and orders.
Facebook Ads for Dog Trainers: The Complete 2026 Strategy Guide
Learn how to use Facebook ads to generate high-quality leads for your dog training business in 2026. Complete strategy guide with targeting, lead magnets, and budget optimization.
Facebook Ads for Roofers: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for roofers in 2026. Discover proven targeting strategies, ad types, and campaign funnels that generate high-quality roofing leads.