Forum Discussion
Weighted average
- 6 years ago
first you need to summerize your table to bring the QTY and FACTOR inline
go to Modeling at the top of the page and then select new table.
in the formula bar enter the code below
Calculated_Table = SUMMARIZE('Table', 'Table'[Entity],"QTY" , Sum('Table'[Quantity]),"FACTOR",sum('Table'[Factor]) )adjust for your actual table names and colunm names
this will output your table with the values inline
EntityQTYFACTOR
A 100 0.5 B 120 0.4 C 112 0.2 add a calculated colunm for the wighted
Column = Calculated_Table[QTY]*Calculated_Table[FACTOR]
then create a measure to dum these and devide by sum of qty
Measure = DIVIDE(sum(Calculated_Table[Column]),sum(Calculated_Table[QTY]))
final out put
first you need to summerize your table to bring the QTY and FACTOR inline
go to Modeling at the top of the page and then select new table.
in the formula bar enter the code below
Calculated_Table = SUMMARIZE('Table', 'Table'[Entity],"QTY" , Sum('Table'[Quantity]),"FACTOR",sum('Table'[Factor]) )adjust for your actual table names and colunm names
this will output your table with the values inline
EntityQTYFACTOR
| A | 100 | 0.5 |
| B | 120 | 0.4 |
| C | 112 | 0.2 |
add a calculated colunm for the wighted
Column = Calculated_Table[QTY]*Calculated_Table[FACTOR]
then create a measure to dum these and devide by sum of qty
Measure = DIVIDE(sum(Calculated_Table[Column]),sum(Calculated_Table[QTY]))
final out put
Great!! Thanks for the hint. It put me back on track.
I actually was working in Excel Power Query at the moment, I will trasfer my model to PowerBI soon.
I modified the solution a little bit - as I could not find how to use SUMMARIZE in Excel.
1) I used in query editor the "Group By" function:
2) I was able to create a measure Avg_Factor = Sumx(Table1;[Sum_Qty]*[Sum_Fct])/Sum([Sum_Qty])
Works as a charm :)