Where Clauses in Tableau
If you have experience with SQL, you know the WHERE clause is fundamental for filtering data. But when you start using Tableau, you might find yourself asking: where is the WHERE clause? You drag dimensions and measures onto shelves, but there isn't an obvious place to just write a query. This is a common point of confusion, but the short answer is that filtering happens in a different, more visual way in Tableau — most of the time.
This tutorial will clear up the confusion about WHERE clauses in Tableau. We’ll cover how the concept of "WHERE" is applied within Tableau's interface and the two specific scenarios where you will actually write something that functions just like a classic SQL WHERE clause: inside calculated fields and within Custom SQL.
How Filtering Usually Works in Tableau (Without WHERE)
Before diving into where to use a WHERE clause, it's important to understand Tableau's primary filtering methods. For 90% of your daily tasks, you won't be writing code. Instead, you'll use the intuitive drag-and-drop interface.
Think of the Filters shelf in your Tableau worksheet as the main home for filtering. You can filter your data in several ways:
- Dimension Filters: Drag a categorical field (like Region, Customer Name, or Product Category) to the Filters shelf. Tableau will present you with a list of values to include or exclude. For example, you can check boxes to only show data for the 'East' and 'West' regions.
- Measure Filters: Drag a numerical field (like Sales, Profit, or Quantity) to the Filters shelf. Tableau will ask you how you want to aggregate the measure (e.g., SUM, AVG) and then provide options to filter based on a range of values, a minimum value, or a maximum value. You could, for instance, show only orders with
SUM(Sales)greater than $50. - Date Filters: When you filter by a date field, Tableau provides powerful options to select relative dates (e.g., "Last 3 months," "This year") or a specific range of dates.
These methods are powerful because they're visual, interactive, and can be exposed to end-users in a dashboard. However, they operate on the entire visualization. When you need to apply filtering logic inside a single calculation without affecting the rest of the view, that’s when you need to think differently.
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.
Filtering Inside Calculations: Tableau's Version of a WHERE Clause
The most common and powerful way to apply WHERE-style logic in Tableau is within a calculated field. Instead of a dedicated WHERE keyword, Tableau uses IF-THEN statements to achieve the same result: filtering data before an aggregation happens.
This technique is especially critical when working with Level of Detail (LOD) expressions, which allow you to compute aggregations at a different level of granularity than what's currently shown in your view.
A Quick Primer on FIXED LOD Expressions
A FIXED LOD expression tells Tableau to compute a value at a specific level, regardless of the dimensions in the view. Its syntax is { FIXED [Dimension(s)] : AGGREGATE([Measure]) }.
For example, { FIXED [Region] : SUM([Sales]) } will calculate the total sales for each region. Even if you only have an individual city showing in your visualization, this calculation will always return the total sales for the entire region that city belongs to.
Example: Calculating Sales for a Specific Category
Let’s say you’re building a dashboard that shows the total sales for every Sub-Category. But for comparison, you also want to display the company's total sales for the entire Technology category in a separate column right next to it.
If you simply drag the Category dimension to the Filters shelf and select 'Technology', your entire view will be filtered, hiding all other sub-categories. That’s not what we want. We need a calculation that internally filters for 'Technology' sales.
Here’s how you do it step-by-step:
- Create a Calculated Field: Go to the Data pane, click the dropdown arrow, and select "Create Calculated Field." Name it something like "Technology Sales."
- Write the Calculation: In the formula box, you'll write an aggregation that includes an
IF-THENstatement. ThisIFstatement acts as your WHERE clause.
SUM(IF [Category] = 'Technology' THEN [Sales] END)- Analyze the Formula:
IF [Category] = 'Technology' THEN [Sales] END: This part of the formula is the powerhouse. It tells Tableau: "Look at every single row of data. If the 'Category' is 'Technology,' return the 'Sales' value for that row. Otherwise, return NULL." This is conceptually identical to writingWHERE Category = 'Technology'in SQL.SUM(...): TheSUMfunction then wraps around this logic, aggregating only the sales values that passed the "WHERE" condition, while all the NULLs are ignored.
When you drag this new "Technology Sales" calculated field into your view, it will show the sum of technology sales, and you can display it alongside other aggregations without filtering them out.
Powering Up with a FIXED LOD:
You can make this even more powerful by combining it with a FIXED LOD to get the grand total of Technology sales on every single row.
The calculation would be:
{ FIXED : SUM(IF [Category] = 'Technology' THEN [Sales] END) }Now, no matter how you slice your view (by sub-category, by year, by region), this field will always show the same number: the total revenue from the Technology category across the entire dataset. This is perfect for calculating what percentage of a sub-category's sales contributes to the total Technology sales.
Using a True WHERE Clause with Custom SQL
There is also a place in Tableau where you can write a WHERE clause exactly as you would in standard SQL: the Custom SQL editor. You use this when you first connect to your data.
Custom SQL allows you to write your own query to SELECT, join, and filter your data before it is ever imported into Tableau's workspace. This is useful for performance reasons or for complex data shaping that’s easier to do in SQL.
When to Use Custom SQL for Filtering
Consider using a WHERE clause in Custom SQL when:
- You are working with a massive dataset. Filtering data at the database level can be much faster than pulling millions of rows into Tableau and then filtering them.
- You know you will never need the filtered-out data. If you're creating a report specifically for the 'West' region, you can add
WHERE [Region] = 'West'to your Custom SQL query to reduce the dataset's size from the start. - You need to perform complex logic that’s simpler in SQL than in Tableau calculations. Sometimes, a few lines of SQL are just more direct than nested LODs and table calculations.
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.
How to Use Custom SQL in Tableau
- Open a new workbook and connect to your data source (e.g., Microsoft SQL Server, PostgreSQL, or even an Excel file).
- In the Data Source tab, find the option for "New Custom SQL" and drag it onto the canvas.
- A SQL editor will open. Here, you can write your query.
For example, you could write a query that only pulls orders over $100 from your sales table from 2023:
SELECT
[OrderID],
[OrderDate],
[Product],
[Sales]
FROM [Orders]
WHERE [Sales] > 100 AND YEAR([OrderDate]) = 2023Once you click "OK", Tableau will only have access to the data that meets these conditions. The key downside is that this filter is "baked in" — dashboard users cannot change it, and if you later decide you need to see sales under $100, you have to go back and edit the Custom SQL query itself.
Choosing the Right Method: Embedded vs. Custom SQL
So when should you use an in-sheet calculated field versus a Custom SQL query? Here’s a simple guide:
- Choose a Calculated Field with IF-THEN logic when you need dynamic and flexible filtering. This is the more common and "Tableau-native" method. It allows you to create comparative analyses (e.g., filtered vs. unfiltered data) and empowers dashboard users to interact with the filters.
- Choose Custom SQL with a WHERE clause when you need to permanently reduce your data for performance reasons or want to do complex data shaping before analysis. Think of it as creating the foundational dataset for your entire workbook.
Final Thoughts
While Tableau doesn't feature a "WHERE clause" as a drag-and-drop tool, the concept is very much alive. For flexible, in-sheet analysis, the IF-THEN statement inside of a calculated field acts as your filter. For pre-filtering large datasets at the source, the classic WHERE clause is ready for you in the Custom SQL SQL editor.
Learning when and how to filter data inside calculations is a huge step toward mastering tools like Tableau. But the learning curve can be steep, often involving complex functions and LOD expressions just to answer a simple business question. At https://www.graphed.com/register, we created a solution where you can skip the technical syntax entirely. Instead of figuring out FIXED LODs or writing Custom SQL, you can just connect your data and ask in plain English: "What were my total sales for technology last quarter?" and get a live, interactive chart in seconds.
Related Articles
How to Create Facebook Ads API for Claude Code
Create a Meta Marketing API access token that never expires, using a system user, so Claude Code can pull Facebook ad reports and manage campaigns.
ClickHouse vs Postgres: When to Switch to Columnar
Comparing ClickHouse vs PostgreSQL means matching storage architecture to workload. Row storage wins for transactions. Columnar wins for scan-heavy analytics.
Google Ads for Orthodontists: Get More Booked Consults
Most orthodontic Google Ads campaigns waste money on low-intent searches. The problem is structure, not the platform.