Covariance is a measure of how two variables are related to one another and has a wide array of applications, from feature extraction (machine learning) to meteorology, molecular biology, financial economics, and more. Covariance can either be positive or negative. Positive covariance means that the two variables are directly related. In other words, the large values in the first variable generally correspond with large values in the second variable and the small values in the first variable generally correspond with the small values in the second variable. Negative covariance means that the two variables are inversely related. This means that the large values in the first variable generally correspond with the smaller values in the second variable and that the smaller values in the first variable generally correspond with the larger values in the second variable. It must be stressed here that covariance does not generally measure the strength of the relationship, just whether the relationship is directly or inversely related.
The formula for covariance is as follows:
If you do not speak math, what we are doing is that for every value of the variables x and y, we are subtracting the value of x from the average (mean) of x, subtracting the value of y from the average (mean) of y, multiplying these two numbers together and dividing by the total number (count) of our variable pairs. We sum all of these numbers, and this becomes our value of covariance.
This recipe demonstrates how to calculate covariance using DAX.