How to Divide Aggregate and Non-Aggregate in Tableau
Almost every Tableau user has been there: you’re trying to create a simple calculated field, like a profit margin, and you’re stopped cold by a cryptic error message: "Cannot mix aggregate and non-aggregate arguments with this function." This common roadblock can be confusing, but it points to a fundamental concept in how Tableau processes data. This article will break down exactly what aggregate and non-aggregate data are, why this error occurs, and four practical methods you can use to solve it.
Understanding Aggregate vs. Non-Aggregate Measures
Before you can fix the error, it's essential to understand the two types of data at play. Tableau views data at different levels of detail, and knowing the difference between a single record and a summary of records is the key.
What is Non-Aggregate Data? (Row-Level)
Non-aggregate data is your raw data, existing at the most granular level possible in your data source. Think of a simple sales spreadsheet. Each row represents a single transaction or record.
For example, in a dataset of orders, you would have columns like:
- Order ID: 1001, 1002, 1003
- Sale Amount: $50, $75, $30
- Quantity: 2, 3, 1
Each individual value in the 'Sale Amount' or 'Quantity' column is a non-aggregate, or row-level, measure. It has not been summarized or combined with any other data. When you drag a field like 'Sale Amount' into your Tableau view, it will initially come in as a disaggregated measure, showing a mark for every single row in your dataset.
What is Aggregate Data? (Summarized-Level)
Aggregate data is the result of a calculation performed on a group of non-aggregate, row-level values. When you take a set of rows and compute a single value from them, you are creating an aggregate.
Common aggregations include:
- SUM(): Calculates the total of all values. Ex:
SUM([Sale Amount])gives you total revenue. - AVG(): Calculates the average. Ex:
AVG([Quantity])gives you the average items per order. - COUNT(): Counts the number of rows. Ex:
COUNT([Order ID])gives you the total number of orders. - MIN() / MAX(): Finds the minimum or maximum value. Ex:
MIN([Sale Amount])finds the smallest sale.
When you drag a measure onto the Rows or Columns shelf in Tableau, it defaults to an aggregation — usually SUM(). That’s why you see SUM(Sales) instead of just Sales. Tableau is summarizing the dozens, hundreds, or thousands of individual sales rows into a single value based on the dimensions in your view (like Category or Region).
Why Tableau Throws the "Cannot Mix" Error
The error arises from a logical conflict. You're asking Tableau to perform an operation where the levels of detail don't match. An aggregated value lives at a summarized level (e.g., total sales for the 'Technology' category), while a non-aggregated value lives at the row level (e.g., the sale amount for one specific laptop order).
Consider this common but incorrect calculation for profit margin:
[Profit] / SUM([Sales])Here’s why it fails:
[Profit]is a non-aggregate value. Tableau tries to find this value for each individual row in your dataset.SUM([Sales])is an aggregate value. Tableau first calculates the total of all sales rows currently in the visualization.
Tableau can't divide a single row's profit by the total sales of the entire dataset because it doesn’t know how to perform that operation logically across every row simultaneously. It’s like trying to divide one student’s test score by the average score of the entire school district and expecting a meaningful number for every student. The levels are mismatched.
To fix this, you must make both sides of the calculation either aggregate or non-aggregate.
4 Ways to Fix the Aggregate/Non-Aggregate Error
Luckily, Tableau provides several powerful ways to align your calculation levels. The best method depends on the question you're trying to answer.
Method 1: Aggregating the Non-Aggregate Value (The Go-To Fix)
This is the most common and often a straightforward solution. The goal is to make all fields in your calculation aggregates. If your intent is to create a summary metric like overall profit margin, you should aggregate the non-aggregate part of your formula.
Let's correct our previous example:
The Problem Formula:
[Profit] / SUM([Sales]) // Error!The Solution:
Wrap the non-aggregate field, [Profit], in an aggregation function like SUM():
SUM([Profit]) / SUM([Sales]) // Works!This calculated field now computes the total profit, then computes the total sales, and then divides those two summarized values. Both parts of the calculation are now at the same aggregated level, and Tableau can execute the formula without issue. This works perfectly for summary-level KPIs.
Method 2: Using a Level of Detail (LOD) Expression
What if you need to perform a calculation at the row level but still reference a dataset-wide total? For example, you want to calculate what percentage of total company sales each individual transaction represents. This is where Level of Detail (LOD) expressions become incredibly powerful.
LOD expressions allow you to compute an aggregate value outside the immediate context of your worksheet's dimensions and filters. You can use it to create a non-aggregate value from an aggregated one.
The Goal: Calculate individual order sales as a percentage of total sales.
The Problem Formula:
[Sales] / SUM([Sales]) // Error!The Solution with a FIXED LOD:
Create a calculated field that computes the total sales for the entire dataset using a FIXED LOD. A FIXED expression computes a value at a specified dimension, or for the entire dataset if no dimensions are specified.
{ FIXED : SUM([Sales]) }This expression calculates the sum of sales across your entire dataset and returns that single value back to every single row. Now, that total sales figure exists at the row level. You can use this new non-aggregate value in your original calculation:
[Sales] / { FIXED : SUM([Sales]) } // Works!Now, both sides are at the same non-aggregate (row) level, solving the error and allowing you to analyze each row's contribution to the total.
Method 3: Using the ATTR() Function
The Attribute function, ATTR(), is a special type of aggregation. It tests if a field has a single, unique value within the current context of the view. If it does, ATTR() returns that value. If the field has multiple values (e.g., minimum and maximum are different), it returns an asterisk (*).
This method works best when you are using a dimension that should only have one value at your view's level of detail, but Tableau still sees it as a non-aggregate field.
The Goal: Divide total monthly sales by a monthly sales target. Imagine you have another data source where [Sales Target] is defined once per month.
The Problem Formula:
SUM([Sales]) / [Sales Target] // Error!You can't divide an aggregate (SUM([Sales])) by a non-aggregate ([Sales Target]). However, since your view is broken down by month, there is only one [Sales Target] value for each mark (each month). You can use ATTR() to let Tableau know it can treat it as a single value.
The Solution with ATTR():
SUM([Sales]) / ATTR([Sales Target]) // Works!Because there is only one [Sales Target] per month, ATTR([Sales Target]) will correctly return that single value, and the calculation will succeed. If you tried this on a view with weekly data where a monthly goal was applied, ATTR() would return *, and the calculation would fail, protecting you from incorrect analysis.
Method 4: Using Table Calculations
Table calculations are computed after the initial aggregations are performed. They operate on the table of aggregated data currently visible in your worksheet. This is another way to perform calculations where all components are at an aggregated level.
The Goal: Calculate each product category's sales as a percentage of the grand total sales in the view.
The Solution with a Table Calculation:
SUM([Sales]) / TOTAL(SUM([Sales])) // Works!Here’s what’s happening:
SUM([Sales])is a regular aggregation, giving you the total sales for that mark (e.g., for the 'Furniture' category row).TOTAL(SUM([Sales]))is a table calculation. It computes the total of the expression (SUM([Sales])) across the entire window partition (which by default is the entire table).
Since both parts of the operation work on aggregated data, there is no error. You would then right-click this calculated field in your view and adjust the "Compute Using" setting (e.g., Table (Down)) to control how the TOTAL() function is calculated.
Final Thoughts
The "cannot mix aggregate and non-aggregate" error in Tableau is a rite of passage for new users, but it points to the tool's logical and powerful data engine. By ensuring your calculations operate on the same level of detail - either by wrapping fields in aggregations like SUM() or using functions like LODs and ATTR() - you can easily overcome this hurdle and perform sophisticated analysis.
Mastering these concepts is part of the learning curve with powerful BI tools, but it often involves learning specific syntax and functions just to get simple answers. At Graphed, we built our AI data analyst to remove this kind of friction entirely. Instead of wrestling with calculated fields, LODs, or aggregation errors, you can connect your data sources and ask questions in plain English - like "what's my profit margin by product category compared to last month?" - and instantly get an interactive, real-time dashboard. We handle the analytics, allowing you to get from question to insight in seconds, not hours.
Related Articles
How to Connect Facebook to Google Data Studio: The Complete Guide for 2026
Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.
Appsflyer vs Mixpanel: Complete 2026 Comparison Guide
The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.
DashThis vs AgencyAnalytics: The Ultimate Comparison Guide for Marketing Agencies
When it comes to choosing the right marketing reporting platform, agencies often find themselves torn between two industry leaders: DashThis and AgencyAnalytics. Both platforms promise to streamline reporting, save time, and impress clients with stunning visualizations. But which one truly delivers on these promises?