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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@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


@ 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!:
The Definitive Guide to Power Query (M)

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

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

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])

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

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?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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