How to Do Linear Regression in Tableau

Cody Schneider8 min read

Trying to show the relationship between two business metrics, like your ad spend and revenue, can feel like a complex statistical problem. But with the right tool, you can visualize this connection in minutes using linear regression. This article will walk you through exactly how to create, interpret, and use a linear regression model in Tableau to find meaningful patterns in your data.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

What is Linear Regression (and Why Should You Care)?

At its core, linear regression is a statistical method used to model the relationship between two variables. That’s it. You have an independent variable (the one you think is causing a change) and a dependent variable (the one that might change as a result). The goal is to see if a straight line - a "trend line" - can describe this relationship.

Let's use a common business example: You want to know if there's a connection between your monthly advertising budget and your monthly sales.

  • Your independent variable is Ad Spend. You control this, and you want to see how changing it impacts another metric.
  • Your dependent variable is Sales. You suspect this number depends on how much you spend on ads.

Linear regression draws a line of best fit through your data points on a chart, helping you answer questions like:

  • "As our ad spend increases, do our sales tend to increase, too?"
  • "Roughly how much more in sales can we expect for every extra $1,000 we put into advertising?"
  • "How confident can we be that this relationship isn't just random noise?"

It’s a powerful way to move from just looking at raw numbers to understanding the relationships between them, which is essential for making smarter budget decisions and forecasting future performance.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Preparing Your Data for Linear Regression

Before you jump into Tableau, a quick check of your data will save you headaches later. The most important requirement for linear regression is that you have two continuous numeric variables. These are typically called "Measures" in Tableau.

For our example, you'd want a dataset that looks something like this:

Month, Ad Spend, Sales
Jan, $10000, $50000
Feb, $12000, $58000
Mar, $15000, $65000
Apr, $11000, $54000
...and so on.

Here, "Ad Spend" and "Sales" are your two measures. The data doesn't have to be perfectly clean, but glaring errors or empty cells can skew your results. Taking a moment to ensure your key columns are formatted as numbers and are complete will lead to a more reliable analysis.

Step-by-Step: How to Do Linear Regression in Tableau

Once your data is ready, creating the model in Tableau is remarkably simple. It really boils down to two main steps: creating a scatter plot and then adding a trend line.

Step 1: Connect Your Data Source

Open Tableau and connect to your data file, whether it's a spreadsheet (like Excel or Google Sheets), a database, or another source. Tableau will display your data fields in the left-hand sidebar under "Tables." Columns with numbers will usually be categorized under "Measures," which is what you'll need.

Step 2: Create a Scatter Plot

The foundation of a linear regression analysis in Tableau is a scatter plot. This type of chart visually displays each of your data records as a single dot, positioned based on its X and Y values.

  1. Find your independent variable (e.g., "Ad Spend") under Measures and drag it to the Columns shelf at the top of the worksheet.
  2. Find your dependent variable (e.g., "Sales") and drag it to the Rows shelf.

Instantly, Tableau will produce a single mark on the chart. This is because it defaulted to showing the SUM() of ad spend and sales. To fix this, you need to show each individual data point.

Go to the Analysis menu at the top and uncheck "Aggregate Measures." Now you should see a scatter plot with several dots, where each dot represents a row from your data source (e.g., one month's ad spend and sales).

Already, you should be able to get a feel for the relationship. Do the dots seem to go up and to the right? Down and to the right? Or are they just scattered about randomly?

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Step 3: Add the Trend Line

Now for the main event. This is where linear regression comes into play.

  1. Navigate to the top-left sidebar and switch from the "Data" pane to the "Analytics" pane.
  2. You'll see a list of analytical objects you can add to your view. Find Trend Line and drag it onto your chart.
  3. A small box will appear asking you which type of model to use. Drop the Trend Line object onto the Linear option.

That’s it! Tableau will automatically draw a straight line through your data points. This is your linear regression model, visually representing the trend in your data.

Interpreting Your Tableau Trend Line

Creating the line is easy, but the real value comes from understanding what it's telling you. Tableau makes this easy to access.

Demystifying the Model Equation

Hover your cursor over any part of the trend line. A tooltip will pop up showing you important statistical details. The most important parts are the equation, the R-squared value, and the P-value.

The equation will look something like this:

Sales = 5.234 * [Ad Spend] + 2530

Let's break that down:

  • Sales: This is your dependent variable.
  • 5.234: This is the slope of the line. It's the most powerful number here. In this example, it means that for every additional $1 you spend on ads, you can expect an increase of approximately $5.23 in sales.
  • [Ad Spend]: This is your independent variable.
  • 2530: This is the y-intercept. It's the theoretical value of your sales if ad spend were $0. Think of it as your baseline sales from other sources.

R-Squared and P-value, Explained Simply

The tooltip also shows two other crucial metrics: R-Squared and the P-value.

  • R-Squared (R²): This value tells you how much of the variation in your sales can be explained by the variation in your ad spend. It ranges from 0 to 1 (or 0% to 100%). A higher R-squared is generally better. An R-squared of 0.78, for example, would mean that 78% of the changes in sales can be attributed to your ad spend, based on this model. The other 22% is due to other factors.
  • P-value: This value tells you if your result is statistically significant. A common rule of thumb is that a P-value less than 0.05 is significant. If your P-value is small (like 0.001), it means there's a very low probability that the relationship you're seeing is just a result of random chance. You can be more confident that there’s a real connection between the variables.

Common Pitfalls and Best Practices

Running a linear regression in Tableau is straightforward, but here are a few tips to make sure you're using it correctly.

Don't Confuse Correlation with Causation

This is the golden rule of statistics. Just because your analysis shows a strong relationship between ad spend and sales, it doesn't prove that more spending causes more sales. There could be another factor at play (an improving economy, a seasonal trend, etc.) that affects both. Linear regression shows you the what, not necessarily the why.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Look Out for Outliers

A single extreme data point - an outlier - can dramatically pull the trend line in its direction and skew your entire model. If you notice one data point far away from all the others, it's worth investigating. Was it a data entry error? A special one-time event like a Black Friday sale? You might consider excluding it from your model to get a more accurate picture of your typical performance.

The Relationship Must be Linear

Linear regression draws a straight line. If your scatter plot data naturally forms a curve (e.g., sales start high with little ad spend, then flatten out no matter how much you spend), a linear model won't fit well. In that case, Tableau offers other trend line models like logarithmic or polynomial to better fit an observable pattern.

Final Thoughts

At the end of the day, running a linear regression analysis in Tableau is a simple process that unlocks a much deeper understanding of your data. By creating a scatter plot and adding a trend line, you can quickly move beyond surface-level metrics to see how your different business drivers truly influence one another.

Once you are ready to make data modeling even more efficient and intuitive for your entire team, give Graphed a look. Instead of working through BI tool interfaces, we make data analysis a simple conversation. You can connect your marketing and sales data sources in seconds and then just ask an AI-powered data analyst questions in plain English - like "show me the relationship between my Facebook Ad spend and Shopify sales" or "create a dashboard of my sales pipeline from HubSpot sliced by rep" - and Graphed builds the charts for you in real time.

Related Articles