Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query List.Covariance Function: How to Use It

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Power Query List.Covariance function calculates the covariance between two lists of numeric values, showing how changes in one list relate to changes in another. It is useful for identifying linear relationships in data, such as sales versus advertising spend or temperature versus energy usage. No external tools or add-ins are required — this function is built into Power Query in Excel, Power BI, and other Microsoft data platforms that support M language. To use it, you must have two lists of equal length containing only numbers.

What You'll Need

  • A dataset loaded into Power Query with at least two columns of numeric data
  • Power Query editor open in Excel (2016 or later) or Power BI Desktop
  • Basic familiarity with transforming columns in Power Query (e.g., extracting, renaming, filtering)
  • Both lists must contain only numbers — no text, blanks, or errors

Step-by-Step

  1. Open your Excel workbook or Power BI Desktop file and load your data into Power Query by selecting your data range and choosing From Table/Range (Excel) or Get Data (Power BI).
  2. In the Power Query Editor, ensure your dataset has two columns with numeric values you want to analyze. Rename them if needed (e.g., Sales and MarketingSpend) using the column header double-click or right-click > Rename.
  3. Click Transform > Group By. In the dialog, select one of your columns (e.g., Sales) as the grouping column, then choose All Rows as the operation. This creates a new column with a table for each group — we’ll use this to extract lists.
  4. Click the double-arrow icon in the new grouped column header and select Expand to New Rows. This restores your original row structure but now includes the grouped context.
  5. Go to the Add Column tab and select Custom Column. Name the new column List1 and enter the formula: Table.Column(#"Previous Step Name", "Sales"). Replace "Previous Step Name" with the actual name of your last step (e.g., "Removed Other Columns") and "Sales" with your column’s name. Repeat for the second column, naming it List2.
  6. Now, go to the Transform tab and select Convert to List for each of your two custom columns. This converts the column values into a list object. You’ll see the data type change from Table to List in the column header.
  7. Click New Column > Custom Column again. Name it Covariance and enter: List.Covariance(List1, List2). Press OK.
  8. Remove any unnecessary columns (right-click > Remove) so only the covariance result remains. Click Close & Load to return the result to your worksheet or report.

Common Mistakes

  • Using columns with text, nulls, or errors — List.Covariance fails if any value isn’t a number. Always filter out blanks or non-numeric entries before applying the function.
  • Mismatched list lengths — both lists must contain the same number of values. If one list has 50 items and the other has 49, the function returns an error.
  • Incorrect step references — if you rename or reorder steps, the formula Table.Column(#"Previous Step Name", "Sales") breaks. Always use the exact step name as shown in the Applied Steps pane.
  • Trying to apply List.Covariance directly to table columns — the function requires list inputs. You must convert columns into lists first using Convert to List.
  • Assuming covariance equals correlation — covariance indicates direction of relationship but not strength. Always pair it with correlation or standard deviation for full context.

Tips

  • Use Table.SelectRows before converting to lists to remove rows with nulls: Table.SelectRows(YourTable, each not List.Contains({null}, [Sales]) and not List.Contains({null}, [MarketingSpend]))
  • For repeated use, create a custom function: define a function that takes two parameters and returns List.Covariance. Save it in a separate query for reuse across projects.
  • Test your lists manually: use View > Formula Bar to inspect the output of each list before applying List.Covariance. If it shows a table or error, something is wrong.
  • Use Table.Buffer on large datasets before list conversion to improve performance and avoid calculation delays.
  • Combine with List.StandardDeviation to calculate correlation: divide covariance by the product of both lists’ standard deviations.

Troubleshooting

If List.Covariance returns an error, start with the simplest fixes. First, check the Applied Steps pane for red icons — these indicate errors in prior steps. Ensure both lists are numeric: hover over the column header to see the data type. If it says "Text" or "Any", you have invalid entries. Use Remove Rows > Remove Errors to clean both columns. If the error says "We couldn't find the column", your Table.Column reference is outdated — double-click the step name in the Applied Steps pane to confirm its exact spelling. If the covariance result is 0, verify your data has variation — constant values (e.g., all sales = 100) yield zero covariance. If Power Query freezes during calculation, reduce dataset size by filtering to a sample of 100 rows first. If you still see "Expression.Error", restart Power Query or Excel. Corrupted step history can sometimes be resolved by copying your query to a new blank query and rebuilding the steps from scratch.

Frequently Asked Questions

Can I use List.Covariance with more than two lists?

No. The function only accepts two list parameters. To compare three variables, calculate pairwise covariances separately.

Does List.Covariance handle negative numbers?

Yes. Negative values are valid and often indicate inverse relationships (e.g., temperature increase leads to heater usage decrease).

Is List.Covariance the same as Excel’s COVARIANCE.S or COVARIANCE.P?

Yes, List.Covariance in Power Query matches Excel’s COVARIANCE.S (sample covariance), which divides by n-1. It does not calculate population covariance.

Why does my covariance value seem too large or small?

Covariance is scale-dependent. If one variable is in dollars and the other in thousands of units, the result will be large. Normalize or standardize your data first if comparing across different units.

Can I use List.Covariance in Power BI Service (cloud)?

Yes, as long as your dataset refreshes successfully in Power Query and the query contains no unsupported references. The function works identically in cloud and desktop environments.

What happens if one list has all identical values?

The covariance will be zero, indicating no linear relationship. This is correct — if one variable doesn’t change, it cannot covary with another.