(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to create a scatter plot with linear regression in Power BI: step by step

João Barros 29 de September de 2026 5 min read

Learn how to create a scatter plot with linear regression in Power BI to visualize correlations and identify outliers. This technique is useful to show the relationship between two variables and add a trend line calculated with DAX when the native visual is not enough.

Prerequisites

  • Power BI Desktop installed.
  • A simple dataset with at least two numeric measures (e.g.: Sales and Quantity) and a temporal or categorical key.
  • Basic knowledge of DAX and the Query Editor.

Step 1: Prepare the data

Import the data into Power BI and make sure you have numeric columns for X and Y (for example, Quantity as X and Sales as Y). If necessary, create a sample table in the Query Editor or use Excel/CSV.

// Exemplo de tabela simples (CSV) com Product, Quantity, Sales
Product,Quantity,Sales,Date
A,10,200,2024-01-01
B,5,75,2024-01-02
C,20,420,2024-01-03

Step 2: Create base measures

Create measures that represent the X and Y axes. They are usually sums or averages. Examples with sum of Sales and Quantity:

QuantitySum = SUM(Table[Quantity])
SalesSum = SUM(Table[Sales])

If you are analyzing by row (point per product), you can use columns instead of measures. But for aggregations by category, measures are more flexible.

Step 3: Calculate the linear regression in DAX

We will calculate the regression line (y = a + b*x) using DAX formulas for b (slope) and a (intercept). We use measures that consider the current visual context.

// Soma das X e Y no contexto
X_Sum = SUM(Table[Quantity])
Y_Sum = SUM(Table[Sales])

// Contagem de pontos (dependendo do detalhe, pode ser DISTINCTCOUNT de Product)
N = COUNTROWS(VALUES(Table[Product]))

// Média X e Y
X_Mean = DIVIDE([X_Sum], [N])
Y_Mean = DIVIDE([Y_Sum], [N])

// Covariância e variância para o declive b
Cov_XY = SUMX(VALUES(Table[Product]), (SUM(Table[Quantity]) - [X_Mean]) * (SUM(Table[Sales]) - [Y_Mean]))
Var_X = SUMX(VALUES(Table[Product]), (SUM(Table[Quantity]) - [X_Mean]) ^ 2)

Slope_b = DIVIDE([Cov_XY], [Var_X])
Intercept_a = [Y_Mean] - [Slope_b] * [X_Mean]

// Valor da linha de tendência para um ponto (usado para plotar a linha)
TrendY = [Intercept_a] + [Slope_b] * SUM(Table[Quantity])

Notes: use VALUES(Table[Product]) or another granularity appropriate to your model. If the points are per row, adjust to iterate by row ID.

Step 4: Create the scatter plot with points

Insert a Scatter chart in the report. Set:

  • X Axis: QuantitySum (or Quantity column for each point)
  • Y Axis: SalesSum (or Sales column)
  • Details: Product (or the point identifier)
  • Size: (optional) another measure, e.g.: SalesSum

This draws the points. If you use aggregations, ensure that the level of detail in the visual matches what you used in the DAX measures (for example, Product or Date).

Step 5: Add the regression line to the chart

The native Scatter chart does not allow calculated lines directly. There are two simple approaches:

  1. Create an auxiliary table with ordered X values and calculate TrendY in DAX; then plot it as a line using a Line and clustered column chart with X on the axis and TrendY as the line series.
  2. Use a custom visual that accepts a line series over points (e.g.: Line and scatter visual from AppSource).

Example for the auxiliary table:

TrendTable = 
VAR MinX = MINX(ALL(Table), Table[Quantity])
VAR MaxX = MAXX(ALL(Table), Table[Quantity])
VAR Step = 1
RETURN
ADDCOLUMNS(
    GENERATESERIES(MinX, MaxX, Step),
    "Quantity", [Value],
    "TrendY", [Intercept_a] + [Slope_b] * [Value]
)

Then create a line visual: Axis = Quantity (from TrendTable), Values = TrendY; to present together, you can align scales or use a combined visual that accepts both tables.

Step 6: Format and handle common errors

Format the axes for readability and check these common errors:

  • Division by zero in Slope_b: prevent using DIVIDE and checks on [Var_X].
  • Inconsistent granularity: measures using different VALUES produce incorrect results; unify the detail level (Product, Date).
  • Overlapping points: use Size and Tooltip to distinguish or apply jitter in the auxiliary set (slight displacement in X).

Verify the result

Confirm that the points reflect the records and that the trend line follows the point cloud. Check extremes and manually calculate a couple of points to confirm the equation y = a + b*x. Use Tooltips and a table visual with Quantity, Sales, TrendY to compare values point by point.

Conclusion

Now you have a scatter plot with a regression line calculated in DAX, useful for correlation analysis and outlier detection. Next steps: try weighted regression, R² in DAX or use a custom visual to overlay line and points. Tip: start with few points and increase granularity only after validating the measures.