Forum Discussion
Matrix multiplication using measures
- 1 year ago
Anonymous Ensure that you have relationships set up between your vol and correlation tables based on the id columns.
First, create a measure to calculate the variance for each id in the vol table.
dax
Variance =
VAR CurrentID = SELECTEDVALUE(vol[id])
RETURN
CALCULATE(
SUMX(
vol,
IF(vol[id] = CurrentID, vol[value]^2, 0)
)
)Next, create a measure to calculate the covariance using the correlation table and the variance measure.
dax
Covariance =
VAR CurrentIDRow = SELECTEDVALUE(correlation[id_row])
VAR CurrentIDColumn = SELECTEDVALUE(correlation[id_column])
VAR VolRow = CALCULATE(SUM(vol[value]), vol[id] = CurrentIDRow)
VAR VolColumn = CALCULATE(SUM(vol[value]), vol[id] = CurrentIDColumn)
VAR CorrelationValue = CALCULATE(SUM(correlation[value]), correlation[id_row] = CurrentIDRow && correlation[id_column] = CurrentIDColumn)
RETURN
VolRow * VolColumn * CorrelationValueAdd a Matrix visual to your Power BI report.
Place id_row from the correlation table in the Rows.
Place id_column from the correlation table in the Columns.
Place the Covariance measure in the Values.
Thanks bhanu_gautam! Your solution is perfect.
Out of curiosity, if for some apparent reason I need to sum up the covariance measure to show 1x1 value so that it can fit on a card visual (look at images below), may I know how it can be done?
i.e., Sum up all the values in covariance values in the matrix
So that the summed value can be shown in the card