Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Weighted Average

ABCDE
1Ao10.8
2Ao2120.5
3Ao230.2
4Ao451
5Bo3430.3
6Bo320.4
7Bo2340.5
8Bo2130.6
9Cv650.7
10Cv6780.8
11Cv5640.6
12Av230.6
13Av120.6
14Av320.6
15Av110.6
16Ev220.6

 

I have the above table ... I wanted to calculate the weighted avarage by the following and as the report will be

 

filter by column "C" if its [all]

for A =(1/(1+212+23+45+23+12+32+11+22)*.8)+(212/(1+212+23+45+23+12+32+11+22)*.5) +...etc

 

if "C" = o

for A =(1/(1+212+23+45)*.8)+(212/(1+212+23+45)*.5) +...etc

 

and so..

 

how can I do that in dax

 

 

 

  • Anonymous's avatar
    Anonymous
    9 years ago

    The solution was very easy.. it just needed a littele mathmatics -_-'

     

     A =(1/(1+212+23+45+23+12+32+11+22)*.8)+(212/(1+212+23+45+23+12+32+11+22)*.5) +...etc

    ==>the rule says

    (x/y*w) + (z/y*o) = ((x*w)+(z*o))/y... "y" will be changed dynamicly during any filter... also "x" ,"z", "w" and "o"

    ==>so our first equ is equevelant to 

    ((1*0.8)+(212*.5)..etc)/(1+212+23+45+23+12+32+11+22)

     

    1-((1*0.8)..(212*.5)..etc) ===> this is a calculated column1  =[D]*[E]

    2-((1*0.8)+(212*.5)..etc) ===> this is a measure:=sum([calculated column1])

    3-(1+212+23+45+23+12+32+11+22) ===> this is measure2:= sum([D])

    4-((1*0.8)+(212*.5)..etc)/(1+212+23+45+23+12+32+11+22) ===> this is measure3:= [measure]/[measure2]

    this is it..

     

     

2 Replies

  • Hi Anonymous,

     

    Add this measure to your model:

    Average_Weight =
    MAX ( 'AVerage'[D] ) / CALCULATE ( SUM ( 'AVerage'[D] ), ALL ( 'AVerage' ) )
        * MAX ( 'AVerage'[E] )

    In order to get the context filter to act in the C column you need to add one new column to your model based on the previous measure:

    Average Column = 'AVerage'[Average_Weight]

    Then just add it to your table and add the filters:

     

     

    Regards,

    MFelix

  • Anonymous's avatar
    Anonymous
    Not applicable

    The solution was very easy.. it just needed a littele mathmatics -_-'

     

     A =(1/(1+212+23+45+23+12+32+11+22)*.8)+(212/(1+212+23+45+23+12+32+11+22)*.5) +...etc

    ==>the rule says

    (x/y*w) + (z/y*o) = ((x*w)+(z*o))/y... "y" will be changed dynamicly during any filter... also "x" ,"z", "w" and "o"

    ==>so our first equ is equevelant to 

    ((1*0.8)+(212*.5)..etc)/(1+212+23+45+23+12+32+11+22)

     

    1-((1*0.8)..(212*.5)..etc) ===> this is a calculated column1  =[D]*[E]

    2-((1*0.8)+(212*.5)..etc) ===> this is a measure:=sum([calculated column1])

    3-(1+212+23+45+23+12+32+11+22) ===> this is measure2:= sum([D])

    4-((1*0.8)+(212*.5)..etc)/(1+212+23+45+23+12+32+11+22) ===> this is measure3:= [measure]/[measure2]

    this is it..