Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Weighted Average Calculation

Hi there,   I have reached a roadblock and seeking for help in calculating weighted average for the following data.  The Column Risk2 determines which products are in a risk category and is calcul...
  • AllisonKennedy's avatar
    5 years ago

    You need to provide a Row Context for this to work when there is more than one Group selected. 

     

    Try using: 

    Weighted % = 
    VAR FR = 
    DIVIDE(sum([Risk2]), calculate(COUNT([Risk2]),ALLSELECTED([ITEMCODE])))
    RETURN
    SUMX(VALUES([GROUP]), 
    SWITCH([Group]
    , "A",FR * 0.5 
    , "B", FR * 0.3
    , "C", FR * 0.2
    , "D", FR * 0
    , "E", FR * 0
    ,"F", FR * 0
    ,FR * 0
    )
    )

     

    Also, you can probably use the AVERAGE function instead of DIVIDE, SUM and COUNT.