How to Create a Correlation Matrix in Power BI

Cody Schneider7 min read

Creating a correlation matrix is a fundamental step in exploring your data, hunting for hidden relationships that can drive meaningful business decisions. If you've ever wondered how your ad spend relates to web traffic or if social media engagement truly impacts sales, a correlation matrix gives you the answer. This guide will walk you through exactly how to build a dynamic and visually intuitive correlation matrix in Power BI.

What is a Correlation Matrix Anyway?

A correlation matrix is a table that shows the correlation coefficients between a set of variables. In simple terms, it measures how strongly two things are related and in what direction. This relationship is quantified by a value called the correlation coefficient, which ranges from -1 to +1.

  • A coefficient of +1 indicates a perfect positive correlation. When one variable increases, the other variable increases by a proportionate amount. For example, the more hours you spend running, the more calories you burn.
  • A coefficient of -1 indicates a perfect negative correlation. When one variable increases, the other variable decreases. For example, as the temperature rises, sales of winter coats tend to fall.
  • A coefficient of 0 means there is no linear correlation between the variables. They have no apparent relationship.

In business, you can use a correlation matrix to answer questions like, "Does an increase in email marketing predict a rise in product sales?" or "Is there a negative relationship between customer support response times and customer satisfaction scores?" It’s a powerful tool for initial data exploration, helping you identify which relationships are worth investigating further.

Prepping Your Data for Analysis

Before jumping into Power BI, it's crucial to have your data structured correctly. For building a correlation matrix, you’ll want your data in a simple "wide" table format. This means each row represents a single observation (like a day, a customer, or a transaction) and each column represents a different variable or metric you want to measure.

Imagine you have marketing data. Your table might look like this:

Here are two essential checks before proceeding:

  1. Data Types: Ensure all the columns you want to analyze are numerical data types (e.g., Whole Number, Decimal Number). You can't calculate a correlation on text fields.
  2. Missing Values: Correlation calculations can be skewed by nulls or blanks. Make sure to handle these appropriately, perhaps by filling them with 0, replacing them with the average of the column, or filtering out those rows entirely.

How to Create the Correlation Matrix Using Power Query

The most flexible and efficient way to build a correlation matrix is within Power Query (the "Transform data" section of Power BI). This method performs the calculations before the data is loaded into your model, making for a snappier report. We'll add a custom M code snippet to do the heavy lifting.

Don't worry if you've never written M code. The process is mostly copy-and-paste.

Step 1: Load Your Data and Open Power Query

First, load your data table into Power BI Desktop. Once loaded, click on the Transform data button on the Home ribbon to open the Power Query Editor.

Step 2: Create a Custom Correlation Function

We need to "teach" Power Query how to calculate a Pearson correlation coefficient. We’ll do this by creating a reusable custom function.

  1. In the Power Query Editor, right-click in the empty space of the Queries pane on the left and select New Query > Blank Query.
  2. Rename this new query to something intuitive, like fnCorrelation.
  3. With fnCorrelation selected, click on Advanced Editor in the Home ribbon.
  4. Delete any existing code and paste the following M code into the window:
(list1 as list, list2 as list) as number =>
let
    // Remove nulls from lists and ensure they align
    zippedList = List.Zip({list1, list2}),
    noNullsList = List.Select(zippedList, each _{0} <> null and _{1} <> null),
    list1Clean = List.Transform(noNullsList, each _{0}),
    list2Clean = List.Transform(noNullsList, each _{1}),
    n = List.Count(list1Clean),
    sum_x = List.Sum(list1Clean),
    sum_y = List.Sum(list2Clean),
    sum_xy = List.Sum(List.Transform(noNullsList, each _{0} * _{1})),
    sum_x2 = List.Sum(List.Transform(list1Clean, each _ * _)),
    sum_y2 = List.Sum(List.Transform(list2Clean, each _ * _)),
    numerator = n * sum_xy - sum_x * sum_y,
    denominator = Number.Sqrt((n * sum_x2 - Number.Power(sum_x, 2)) * (n * sum_y2 - Number.Power(sum_y, 2))),
    correlation = if denominator = 0 or n < 2 then 0 else numerator / denominator
in
    correlation

Click Done. You've now created a custom function. It won't show anything yet, but it's ready to be used.

Step 3: Build the Correlation Matrix Using the Function

Now, let's create a new query that uses our function to build the final matrix.

  1. Once again, create a new Blank Query. Rename it to Correlation Matrix.
  2. Open the Advanced Editor for this new query.
  3. Paste in the following code. Important: Replace #"YourTable" on the second line with the actual name of your data table query. Make sure the name is wrapped in #"" if it contains spaces.
let
    Source = #"YourTable", // <-- CHANGE THIS TO YOUR TABLE NAME
    #"Removed Other Columns" = Table.SelectColumns(Source, {"Ad Spend ($)", "Website Sessions", "Leads Generated", "Sales ($)"}), // <-- SELECT YOUR NUMERIC COLUMNS
    Buffer = Table.Buffer(#"Removed Other Columns"),
    ColumnNames = Table.ColumnNames(Buffer),
    // Create the correlation matrix
    CorrelationList = List.Transform(ColumnNames, (x) => 
        List.Transform(ColumnNames, (y) => 
            fnCorrelation(Table.Column(Buffer, x), Table.Column(Buffer, y))
        )
    ),
    // Format into a table
    CorrelationTable = Table.FromRows(CorrelationList, ColumnNames),
    #"Added Index" = Table.AddIndexColumn(CorrelationTable, "Index", 0, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Variable 2"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns", {{"Attribute", "Variable 1"}, {"Variable 2", "Variable 2"}, {"Value", "Correlation"}}),
    #"Added Custom Column" = Table.AddColumn(#"Renamed Columns", "Variable 1", each ColumnNames{[Index]}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom Column",{"Index"})
in
    #"Removed Columns"

A few notes on customizing this script:

  • On line 3 (#"Removed Other Columns"), list the names of all the numerical columns you want to include in your matrix. Make sure the spelling and capitalization are exact.
  • Click Done. You should now see a table with three columns: "Variable 2," "Correlation," and "Variable 1."

Step 4: Load and Visualize in Power BI

Now for the final step! Click Close & Apply in the top-left corner of the Power Query Editor to load your new Correlation Matrix table into your data model.

  1. On the Power BI report canvas, select the Matrix visual from the Visualizations pane.
  2. Drag your new fields into the visual's configuration box:

You'll immediately see a grid populated with your correlation coefficients. Success!

Making it Readable with Conditional Formatting (Heatmap)

A table of numbers is useful, but a heatmap is much easier to interpret at a glance. Let’s add some color-coding to bring your matrix to life.

  1. Select your matrix visual on the report page.
  2. Open the Format your visual pane (the paintbrush icon).
  3. Expand the Cell elements section.
  4. Find the option for Background color and toggle it On.
  5. Click the small fx symbol to open the advanced formatting rules.
  6. In the settings window that appears, configure it as follows:

Click OK. Your stark matrix now transforms into an insightful heatmap. Bright colors will immediately draw your eye to the strongest positive and negative relationships, making data exploration fast and intuitive.

Final Thoughts

Building a correlation matrix in Power BI is a fantastic way to uncover the often-unseen relationships that exist within your performance data. By using Power Query and some clever conditional formatting, you can turn a simple table of metrics into a powerful analytical tool that helps you understand the drivers of your business success.

While creating this manually is a great skill, sometimes you just need to get answers quickly without diving into M code. At Graphed we automate this entire process so you can understand your business using simple natural language. Instead of building matrices from scratch, you can connect your marketing and sales platforms (like Google Analytics, Facebook Ads, Shopify, and Salesforce) and just ask an AI analyst questions like, “Show the correlation between our Facebook ad spend and Shopify revenue,” and get dashboards and insights back in seconds. It bridges the gap between having data and knowing what to do with it, letting you focus on strategy instead of report-building.

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.