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.
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 * CorrelationValue
Add 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.