Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Matrix multiplication using measures

Hello everyone,   I am new to DAX and I need urgent help. I have two datasets (vol and correlation) that I am pulling from my company's cloud database. Sample data are as follows:   vol: id ...
  • bhanu_gautam's avatar
    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 * 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.