Forum Discussion

analyticspbi87's avatar
1 year ago
Solved

Weighted Average while filtering out another column

I was trying to make a chart from the data as follows with the filter on category = A 

CategoryNameYearValue Health ClassClass 2
ACelery202514                                          883VegAB
ACarrot202514.7                                      1,314VegAB
ACabbage20258.6484                                          682VegAC
AAsparagus202519.1529                                          332VegAC
AApple202523.85                                          528FruitAC
AOrange202540.2027                                          544FruitAD
BCelery202516                                          893VegAB
BCarrot202516.7                                      1,324VegAB
BCabbage202510.6484                                          692VegAC
BAsparagus202521.1529                                          342VegAC
BOrange202542.2027                                          554FruitAD

A total for Health = 4283 

A subtotal Veg = 3211

A subtotal Fruit = 1072

 

And I need to subtotal the weight using class F and G separately. So far, for column F - Class, it looks like the following:

The following table is also filtered out by Column A 

Row LabelsSum of Value
Fruit16.03
Apple23.85
Orange40.20
Veg25.11
Asparagus19.15
Cabbage8.65
Carrot14.70
Celery14.00
Grand Total120.55

Fruit subtotal is calculated as follows: =SUM(23.85+40.2027)*(SUM(528+544)/4283)

Veg subtotal is calculated as follows: =SUM(14+14.7+8.6484)*(SUM(883+1314+682)/4283)

 

I've tried the following formula, but it doesn't seem to work

Cam calc =
DIVIDE(SUM('Table'[Health])*'Table'[Value],
SUM('Table'[Health])
)

2 Replies

  • Here's my measure: 

    Cam calc = DIVIDE(
        SUM('Table'[ Health ]) * SUM('Table'[Value]),
        CALCULATE(SUM('Table'[ Health ]), REMOVEFILTERS('Table'[Class]))
    )

    and the result (ignore the Sum of Value column):

     

    btw - I can't get the same results as your example (I just filtered by Category = A; why would Asparagus not be included in the Cam calc measure in the veg subtotal? you might need to change the calculate parameter depending on your specific requirements)