Forum Discussion
Oleg222
5 years agoHelper II
Measure from data in one column
I have table:
Line Indicator Value
A Efficiency 90
B Efficiency 80
A Weight 5
B Weight 10I am trying to plot a metric that calculates the weighted average of some KPIs, but all the data is in one column.
And this measure should return me 83.33, from (90 * 5 + 80 * 10) / (5 + 10).
How can I use DAX to get this result (Without unpivot)?
Oleg222
Can you try this version?Weighted Average = DIVIDE( SUMX( VALUES(Table3[Date]), CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Efficiency1") * CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Weight1") ) , SUMX( VALUES(Table3[Date]), CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Weight1") ) )
16 Replies
- FowmySuper User
Oleg222
Created the measure, please check with your data:Weighted Average = var __num = SUMX( FILTER( Table3 , Table3[Indicator] = "Efficiency" ), var __line = Table3[Line] var __value = Table3[Value] return CALCULATE( SUM(Table3[Value]), FILTER( Table3, Table3[Indicator] = "Weight" && Table3[Line] = __line ) ) * __value ) var __den = SUMX( FILTER( Table3 , Table3[Indicator] = "Efficiency" ), var __line = Table3[Line] return CALCULATE( SUM(Table3[Value]), FILTER( Table3, Table3[Indicator] = "Weight" && Table3[Line] = __line ) ) ) return DIVIDE( __num , __den )- FowmySuper User
Oleg222
Can you try this version?Weighted Average = DIVIDE( SUMX( VALUES(Table3[Date]), CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Efficiency1") * CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Weight1") ) , SUMX( VALUES(Table3[Date]), CALCULATE( SUM(Table3[Value]), Table3[Measures] = "Weight1") ) )
- FrankATCommunity Champion
Hi Oleg222 ,
you can do it with DAX like this:
Weighted Average = VAR _Table = SUMMARIZE ( 'Table', 'Table'[Line], "Efficiency", CALCULATE ( MIN ( 'Table'[Value] ), 'Table'[Indicator] = "Efficiency" ), "Weight", CALCULATE ( MIN ( 'Table'[Value] ), 'Table'[Indicator] = "Weight" ) ) VAR _SUM = SUMX ( _Table, [Efficiency] * [Weight] ) VAR _Result = DIVIDE ( _SUM, SUMX ( _Table, [Weight] ) ) RETURN _ResultWith kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut) - Oleg222Helper II
Sorry friends, one important think (I forgot, my fault) - in column "Line" should stand date.
- Oleg222Helper II