top of page
Search

Correlation Matters! - Understanding Correlation and Calculating Pearson Correlation Coefficient in Power BI

How to calculate correlation coefficient in Power BI?

Generalized DAX code for the Pearson correlation coefficient formula-

```Correlation_coefficient =

var mean_X =calculate(AVERAGE(TableName[xi]))
var mean_Y=calculate(AVERAGE(TableName[yi]))
//numerator
var numerator = SUMX('TableName',( [xi]- mean_X)*([yi]- mean_Y))
//denominator
var denominator = SQRT(SUMX('TableName',([xi]-mean_X)^2)*SUMX('TableName',([yi]- mean_Y)^2))

return
divide( numerator, denominator)
```

Implementing the above to create correlation coefficient measure using DAX-

```Correlation_coefficient =
var mean_X =calculate(AVERAGE(SampleDataset[Weight (KG)]))
var mean_Y=calculate(AVERAGE(SampleDataset[HEIGHT (M)]))

//numerator
var numerator  =  SUMX('SampleDataset',( [Weight (KG)]- mean_X)*([HEIGHT (M)]- mean_Y))

//denominator
var denominator=  SQRT(SUMX('SampleDataset',([Weight (KG)]- mean_X)^2)*SUMX('SampleDataset',([HEIGHT (M)]- mean_Y)^2))

return
divide( numerator, denominator)```