How to perform Linear Regression in Tableau?

Regression analysis is a statistical method used to model and understand the relationship between an independent variable and one or more dependent variables. It’s commonly used for predicting or understanding the impact of changes in the independent variable on the dependent one.  

In simpler terms, regression analysis helps us analyze and quantify relationships between variables, making it an invaluable tool in fields like economics, finance, and beyond.

Today, we’ll explore creating a dashboard to analyze the relationship between Profit and Sales using Tableau’s Sample Superstore dataset.

This step-by-step SkillPill will help you visualize and understand the data, allowing for more informed and strategic decision-making.

Step 1: Connect to Data

In Tableau Desktop connect to SampleSuperstore data provided by Tableau. 

Step 2: Create scatterplot graphics for the trendline example 

→ Create a worksheet named Profit and Sales Trendline 

→ Add Sales on Columns  

→ Add Profit on Rows 

→ Add Customer Name on Details 

→ Go to Analytics and add the trendline line by linear 

Explanation of Profit=0.15*Sales+ (-627.97) -> when the sales are raising with one unit the Profit = 0.15*1+(-627.97) 

Step 3: Create graphics to illustrate the profit distance from the linear model using color intensity

Create a worksheet named Profit Distance based on the model 

→ Create a calculated field named Slope which will calculate the variance by the formula:

WINDOW_COVAR(SUM([Sales]), SUM([Profit]))/WINDOW_VAR(SUM([Sales])). 

→ Create a calculated field named Intercept which will calculate the variance by the formula:

WINDOW_AVG(SUM([Profit]))-WINDOW_AVG(SUM([Sales]))*[Slope]. 

→ Create a calculated field named Calculated Profit where we’ll replicate the Regression formula: 

SUM([Sales])*[Slope] + [Intercept] 

→ Also, we will calculate the Profit distance % by the formula:  

(SUM([Profit])-[Calculated Profit])/[Calculated Profit] 

→ Add Sales on Columns  

→ Add Profit on Rows 

→ Add Customer Name on Details 

→ Add Calculated Profit on Rows 

→ Go to Analytics and add the trendline line by linear 

→ Make the Profit and Calculated Profit dual axis and synchronize then the axis 

→ Right-click on Calculated Profit and add Table Calculation by Customer Name 

→ Go to Marks and Make Calculated Profit  as Line 

→ Go to Marks and add Profit Distance % on Text 

→ Go to Marks and add Profit Distance % on Detail 

→ Go to Marks and add Profit Distance % on Color  

→ Go to Color – Advanced and add Start -1 and End 1 

→ Hide the Calculated Profit Axis by right-clicking and unchecking the show header option 

→ Go on Marks and make a Sum(Profit) circle 

 

Here is the dashboard in Tableau Public:


Watch the video tutorial here:

About btProvider:

We hold all possible technical and sales certifications for all products:

Tableau Desktop, Tableau Public, Tableau Server, Tableau Prep, and Tableau Data Management.

With Tableau Software – the best data visualization platform – you can always understand your business or your job better. Using Tableau, you will make intelligent and strategic decisions and quickly understand the data flow, numbers, and the results it produces. See other #skillpill video tutorials here:

How to display multiple insights on a dashboard in #Tableau

How to create Stacked Bars on Grand Totals in Tableau

How to create a Buffer Zoom in a Tableau Map

Are you interested in learning more about Tableau Software – one of the best analytics tools and implementing the solution in the entire company? 

Contact us!

See how Tableau works, by downloading a free trial here: