Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rampsaladi
Frequent Visitor

Creating Co-variance using DAX

Hi Can anyone help me in getting the covariance statistics function using dax. The following is an example series.

 

AB
111
212
313
414
515
616
717
818
919
1020

Co variance.PNG

Based on the Covariance formula I did an individual average subtracted from the values and mutipled them and divided by the toal N. The problem I see that when i do the Average of the series and use that average to subtract from each value of the series the values I get are different from the values I get when i do the same thing in Excel. Any help in this regard is appreciated

1 ACCEPTED SOLUTION

OK, I created a Quick Measure gallery entry here if you want to follow-up on this:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Covariance/m-p/379069#M115

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@rampsaladi - One question, where did you get that formula for covariance, because it is not necessarily jiving with what I am seeing here:

 

https://en.wikipedia.org/wiki/Covariance

https://math.tutorvista.com/statistics/covariance.html



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks for looking it up quickly, I know there is a Covariance function in Power Query but was not sure how to use it as I have never used the M and as far as the formula is concerend I got it from the below site. 

 

http://mathworld.wolfram.com/Covariance.html

 

I do have the expected value for the co-variance so I will use the DAX that you provided and see how it matches up 

 

 

OK, I created a Quick Measure gallery entry here if you want to follow-up on this:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Covariance/m-p/379069#M115

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

This DAX gives me the same number that I get in Excel, 8.25 for the information given:

 

Covariance = 
VAR AvgA = CALCULATE(AVERAGE('Covariance'[A]),ALL('Covariance'))
VAR AvgB = CALCULATE(AVERAGE('Covariance'[B]),ALL('Covariance'))
VAR MyTable = SUMMARIZE('Covariance','Covariance'[A],"Covariance",([A]-AvgA)*(MAX('Covariance'[B])-AvgB)/CALCULATE(COUNTROWS('Covariance'),ALL('Covariance')))
RETURN SUMX(MyTable,[Covariance])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

There is a List.Covariance function in Power Query. I will look into this for DAX, do you have what the result should be for the information provided?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.