List.Covariance

List

Returns the sample covariance of two lists of numbers.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

List.Covariance(numberList1 as list, numberList2 as list) as nullable number

Parameters

NameTypeRequiredDescription
numberList1listYesThe first list of numbers.
numberList2listYesThe second list of numbers. Must have the same length as numberList1.

Return Value

nullable numberThe sample covariance between the two lists, or null if the lists are empty.

Remarks

List.Covariance computes the sample covariance between two numeric lists. Covariance measures how much two variables change together: a positive value means they tend to increase together, while a negative value means one tends to increase as the other decreases. A covariance near zero suggests little linear relationship.

The formula is the sample covariance: the sum of (x - mean_x) * (y - mean_y) divided by n - 1 (Bessel's correction), where n is the number of paired observations. This is appropriate when the lists represent a sample from a larger population.

Both lists must have the same number of elements; mismatched lengths will cause an error. Returns null if either list is empty. Null values in the lists cause errors — clean the data with List.RemoveNulls first if needed. To normalize covariance into a more interpretable [-1, 1] scale, divide by the product of the two standard deviations to get the Pearson correlation coefficient.

Examples

Example 1: Positive covariance — two variables move together

List.Covariance({2, 4, 6, 8}, {1, 3, 5, 7})
Result
Result
15.33

Example 2: Negative covariance — price increases as volume decreases

let
    Prices = {10, 20, 30, 40, 50},
    Volumes = {500, 420, 350, 260, 180},
    Cov = List.Covariance(Prices, Volumes)
in
    #table({"Covariance"}, {{Cov}})
Applied Steps

The final output — presents the covariance value in a single-row table labeled Covariance.

Covariance
1-2,050

Example 3: Inversely related lists

List.Covariance({1, 2, 3, 4}, {4, 3, 2, 1})
Result
Result
1-1.67

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks