skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
    • Dynamics 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Partners Overview
    • Solutions Partners
    • BI Specialized Partners
    • Power BI CSOs
    • Fabric Partner Community
    • Training
    • Getting started
      • Overview
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Power BI forums
    • Updates
    • News & Announcements
    • Get Help with Power BI
    • Desktop
    • Service
    • Report Server
    • Power Query
    • Mobile Apps
    • Developer
    • DAX Commands and Tips
    • Custom Visuals Development Discussion
    • Health and Life Sciences
    • Power BI Spanish forums
    • Translated Spanish Desktop
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Training and Consulting
    • Instructor Led Training
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    • Ideas
    • Custom Visuals Ideas
    • Issues
    • Issues
    • Events
    • Upcoming Events
    • Community Engagement
    • T-Shirt Design Challenge 2023
    • Community Blog
    • Power BI Community Blog
    • Custom Visuals Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 

    Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

    • Power BI forums
    • Galleries
    • Quick Measures Gallery
    • Covariance

    Covariance

    03-19-2018 08:21 AM - last edited 06-26-2018 09:49 AM

    Super User Greg_Deckler
    Super User
    6536 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Covariance

    ‎03-19-2018 08:21 AM

    From Wikipedia on Covariance: https://en.wikipedia.org/wiki/Covariance

    In probability theory and statistics, covariance is a measure of the joint variability of two random variables.[1] If the greater values of one variable mainly correspond with the greater values of the other variable, and the same holds for the lesser values, i.e., the variables tend to show similar behavior, the covariance is positive.[2] In the opposite case, when the greater values of one variable mainly correspond to the lesser values of the other, i.e., the variables tend to show opposite behavior, the covariance is negative. The sign of the covariance therefore shows the tendency in the linear relationship between the variables. The magnitude of the covariance is not easy to interpret because it is not normalized and hence depends on the magnitudes of the variables. The normalized version of the covariance, the correlation coefficient, however, shows by its magnitude the strength of the linear relation.

     

    The covariance formula from http://mathworld.wolfram.com/Covariance.html is the following:

     

    covariance.gif

     

    Thus, the following DAX measure equation performs this formula on a table (Covariance) with two columns (A and B).

     

     

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

     

     

     

     

     

     

     

     

     

    eyJrIjoiOTU5MWM1M2QtZTdlMy00ZTY4LThkODgtZjU1YzVkOWQ5NjM2IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ 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!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Covariance.pbix
    25 KB
    Labels:
    • Labels:
    • Mathematical
    Message 1 of 3
    6,536 Views
    3
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    sv11
    sv11 Helper I
    Helper I
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎02-08-2019 11:04 AM

    @Greg_Deckler

     

    Thanks for providing this information.

    I have tried to calculate the Covariance based on your DAX code but the system is throwing an error unkown to me. Could you please take a look at the below DAX code? (Errors in Red color)

     

    Covariance = 
    VAR AvgA = CALCULATE(AVERAGE('PeriodSummary-FLEXMUIRRebalancing'[Total Return]), ALL('PeriodSummary-FLEXMUIRRebalancing'))
    VAR AvgB = CALCULATE(AVERAGE('PeriodSummary-FLEXMUIRRebalancing'[Benchmark Return]), ALL('PeriodSummary-FLEXMUIRRebalancing'))
    VAR MyTable = SUMMARIZE('PeriodSummary-FLEXMUIRRebalancing', 'PeriodSummary-FLEXMUIRRebalancing'[Total Return], "PeriodSummary-FLEXMUIRRebalancing", ('PeriodSummary-FLEXMUIRRebalancing'[Total Return] - AvgA)*(MAX('PeriodSummary-FLEXMUIRRebalancing'[Benchmark Return] - AvgB) / CALCULATE(COUNTROWS('PeriodSummary-FLEXMUIRRebalancing'), ALL('PeriodSummary-FLEXMUIRRebalancing')))
    RETURN 

    Thanks

    Message 2 of 3
    5,828 Views
    0
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to sv11
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎02-08-2019 04:36 PM

    I think you are missing a closing paren, in red

     

    Covariance = 
    VAR AvgA = 
    CALCULATE(
    	AVERAGE('PeriodSummary-FLEXMUIRRebalancing'[Total Return]), 
    	ALL('PeriodSummary-FLEXMUIRRebalancing')
    )
    VAR AvgB = 
    CALCULATE(
    	AVERAGE('PeriodSummary-FLEXMUIRRebalancing'[Benchmark Return]), 
    	ALL('PeriodSummary-FLEXMUIRRebalancing')
    )
    
    VAR MyTable = 
    SUMMARIZE(
    	'PeriodSummary-FLEXMUIRRebalancing', 
    	'PeriodSummary-FLEXMUIRRebalancing'[Total Return], 
    	"PeriodSummary-FLEXMUIRRebalancing", 
    	('PeriodSummary-FLEXMUIRRebalancing'[Total Return] - AvgA)
    	*
    	(MAX('PeriodSummary-FLEXMUIRRebalancing'[Benchmark Return]) - AvgB) 
    	/ 
    	CALCULATE(
    		COUNTROWS('PeriodSummary-FLEXMUIRRebalancing'), 
    		ALL('PeriodSummary-FLEXMUIRRebalancing')
    	)
    )
    RETURN 

    @ 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!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Message 3 of 3
    5,818 Views
    1
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices