How to Calculate Correlation Coefficient in Tableau
Figuring out if two variables in your data move together is a fundamental part of analysis. You might want to know if more ad spend leads to more sales, or if an increase in website traffic results in more sign-ups. The correlation coefficient is a single, powerful number that tells you exactly how strong that relationship is, and you can calculate it directly within Tableau. This article will walk you through two simple methods for calculating the correlation coefficient in Tableau so you can get a precise measure of the relationships in your data.
What Exactly is a Correlation Coefficient?
Before jumping into Tableau, let’s quickly cover what this metric represents. The correlation coefficient, often represented as r (specifically, Pearson's correlation coefficient), is a statistical measure that quantifies the strength and direction of a linear relationship between two variables.
It sounds complex, but the output is an easy-to-understand number that always falls between -1 and 1:
- A value of +1 means a perfect positive correlation. As one variable increases, the other variable increases in perfect sync.
- A value of -1 means a perfect negative correlation. As one variable increases, the other variable decreases in perfect sync.
- A value of 0 means there is no linear correlation at all. The variables don't seem to have any discernible linear relationship.
Values between these points show the degree of the relationship. For instance, a correlation of +0.8 indicates a strong positive relationship, while -0.2 suggests a very weak negative relationship. Seeing these numbers helps you move beyond a gut feeling from a chart and provides a concrete metric to work with.
Pre-requisites: Getting Your Data Ready
To calculate a correlation coefficient, you need two things:
- Your data connected to Tableau.
- At least two quantitative measures (continuous numeric fields, shown with a green pill in Tableau) that you want to compare.
For our examples, we will use the Sample - Superstore dataset that comes with Tableau. We’ll be looking for a potential correlation between Sales and Profit.
Method 1: Using the CORR() Function in a Calculated Field
The most direct way to get the correlation coefficient is by using Tableau’s built-in function, CORR(). You'll do this by creating a calculated field. This method is perfect when you need the exact number to display on a dashboard or use in other 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.
Step 1: Build a Scatter Plot to Visualize the Relationship
A scatter plot is the classic visualization for exploring correlation. It helps you see the relationship before you even calculate the number.
- Drag the measure Sales onto the Columns shelf.
- Drag the measure Profit onto the Rows shelf.
Right now, you likely only see one point. That's because Tableau has aggregated all your sales and profit data into a single mark. To see the relationship across different data points, you need to add a level of detail.
- Find a dimension like Order ID or Product Name in the Data pane.
- Drag it to the Detail card on the Marks shelf.
Now you have a scatter plot, and you can visually begin to assess the relationship. For Sales vs. Profit in the Superstore dataset, you should see a general trend where points with higher sales also tend to have higher profit.
Step 2: Create a New Calculated Field
Next, we'll create a calculated field to house our correlation formula.
- In the Data pane on the left, click the small down arrow at the top and select Create Calculated Field.
- Give your calculated field a name, like "Correlation of Sales and Profit".
Step 3: Write the Correlation Formula
In the formula box of the calculation editor, type the following:
CORR([Sales], [Profit])
This formula tells Tableau to calculate the correlation coefficient between the aggregated values of the Sales and Profit fields for the marks in the view. Click OK when you’re done.
Step 4: Add the Calculation to Your View
Now you have a new measure in your Data pane called "Correlation of Sales and Profit." To see the result, you can display it in the chart’s title or tooltip.
For the Tooltip:
- Drag your new "Correlation of Sales and Profit" calculated field onto the Tooltip card on the Marks shelf.
- Now, when you hover over any data point in your scatter plot, the tooltip will display the overall correlation coefficient.
For the Title:
- Double-click the Sheet Title (usually "Sheet 1" by default) to edit it.
- In the editor, click Insert, find your "Correlation of Sales and Profit" field, and select it. This will embed the calculated value directly into your title.
You should now see the correlation coefficient value displayed. This single number gives you a precise measurement of the association you visualized in the scatter plot.
Method 2: Using Trend Lines to Find R-Squared
Another way to analyze correlation is by using Tableau’s built-in analytics features, specifically the trend line. This method is more visual and provides extra statistical context, though it requires one small extra calculation on your part.
Step 1: Create Your Scatter Plot
Start with the same scatter plot we created in the first method: Sales on Columns, Profit on Rows, and a dimension like Order ID on Detail.
Step 2: Add a Trend Line
Next, switch from the Data pane to the Analytics pane (the tabs are at the top left).
- Under the Model section, find Trend Line.
- Drag and drop it onto your worksheet, and place it on the Linear option that appears.
A dotted line will immediately appear, tracing the linear trend through your data points.
Step 3: Analyze the Trend Line Description
Now for the important part. Hover your mouse over any part of the trend line. A tooltip will appear with key statistical information about the model, including:
- The equation for the line
- The R-Squared value
- The P-value
Here, we are interested in the R-Squared value. R-Squared tells you how much of the variation in your dependent variable (Profit) can be explained by your independent variable (Sales). Its value is literally the correlation coefficient (r) squared.
Step 4: Calculate the Correlation Coefficient from R-Squared
To find the correlation coefficient (r), you simply need to take the square root of the R-Squared value.
For example, if the trend line tooltip shows R-Squared = 0.22, you would calculate:
Correlation Coefficient (r) = √0.22 ≈ 0.47
One Important Note: The square root calculation always gives you a positive number. This method won’t automatically tell you if the correlation is positive or negative. You have to determine the direction yourself by looking at the slope of the trend line.
- If the line goes up and to the right, the correlation is positive.
- If the line goes down and to the right, the correlation is negative.
While this method isn't as direct as the CORR() function, it’s great for exploratory analysis because it instantly visualizes the trend while providing the R-Squared and P-value for additional context.
Key Considerations for Correlation Analysis
Calculating the number is easy, but interpreting it correctly requires some thought. Keep these points in mind.
Correlation Is Not Causation
This is the golden rule of statistics. Just because two variables are strongly correlated does not mean one causes the other. There could be a third, hidden factor (a confounding variable) influencing both. For example, ice cream sales and shark attacks are highly correlated, but one doesn't cause the other. The confounding variable is summer weather, which drives more people to both buy ice cream and swim in the ocean.
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 Impact of Granularity and Outliers
The level of detail you use in your analysis can significantly change the outcome. A correlation might be strong at a monthly level but disappear completely when you look at daily data. Outliers — extreme values that sit far away from the rest of your data points — can also heavily skew the correlation coefficient. Always visualize your data in a scatter plot first to spot these potential issues. When you find outliers, you may consider filtering them out to get a more accurate picture of the typical relationship.
Segment Your Analysis
An overall correlation can mask very different relationships within segments of your data. For example, there may be a weak overall correlation between ad spend and sales, but a very strong positive correlation for a specific marketing channel or region. Use Tableau's features to analyze correlation for different segments. An easy way is to drag a dimension like Region or Category onto the Color card on the Marks shelf. This will break your scatter plot into distinct groups, and you can even have Tableau draw a separate trend line for each.
Final Thoughts
Measuring the relationship between variables with a correlation coefficient adds precision to your data analysis. Tableau gives you straightforward tools to do this, whether you prefer the direct calculation with the CORR() function or the more visual approach using trend lines and R-Squared values.
Often, the biggest challenge isn't the calculation itself, but bringing together data from different sources to find these relationships in the first place — like correlating ad spend from Facebook Ads with sales from your Shopify store. To make that process faster, we built Graphed. You can connect all your marketing and sales platforms in a few clicks, then just ask questions in plain English like, "show me the correlation between Facebook Ads spend and new customers from Shopify last quarter" to get instant charts and find the insights you're looking for without the manual work.
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.