Forum Discussion
Power BI Matrix Row Calculations
- 6 years ago
Hi Anonymous ,
Create this measure to show the result:
avg = VAR _sale = CALCULATE ( SUM ( test[Value] ), ALLEXCEPT ( 'test', test[Year], test[Region] ) ) VAR _count = CALCULATE ( SUM ( 'test'[Value] ), ALLEXCEPT ( test, test[Year], test[Region] ), 'test'[Measure] = "Count" ) RETURN IF ( ISINSCOPE ( 'test'[Measure] ), IF ( SELECTEDVALUE ( 'test'[Measure] ) = "Count" || SELECTEDVALUE ( 'test'[Measure] ) = "Sale", SUM ( 'test'[Value] ), _sale / _count ), SUM ( test[Value] ) + _sale / _count )Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
To achieve this, need to create a new table like this:
Use union() to combine two tables:
test = UNION('Table','Avg table')Create a calculated column in 'test' table:
result =
VAR _sale =
CALCULATE (
SUM ( test[Value] ),
ALLEXCEPT ( 'test', test[Year], test[Region] )
)
VAR _count =
CALCULATE (
SUM ( 'test'[Value] ),
ALLEXCEPT ( test, test[Year], test[Region] ),
'test'[Measure] = "Count"
)
RETURN
IF (
'test'[Measure] = "Count"
|| 'test'[Measure] = "Sale",
'test'[Value],
_sale / _count
)Use a Matrix visual to show the result:
Attached my sample file that hopes to help you, please check and try it: Power BI Matrix Row Calculations.pbix
Best Regards,
Yingjie Li
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
I tried using this solution. One issue in my matrix is I need to show Sales and Count as a SUM, but the Result as an Average. How could I do this?
- lbendlin6 years agoSuper User
Don't use these aggregation functions. Instead create separate measures as I suggested. Then you can control the behavior both inside the visual and in the totals (via HASONEVALUE() etc)
- v-yingjl6 years agoCommunity Support
Hi Anonymous ,
Create this measure to show the result:
avg = VAR _sale = CALCULATE ( SUM ( test[Value] ), ALLEXCEPT ( 'test', test[Year], test[Region] ) ) VAR _count = CALCULATE ( SUM ( 'test'[Value] ), ALLEXCEPT ( test, test[Year], test[Region] ), 'test'[Measure] = "Count" ) RETURN IF ( ISINSCOPE ( 'test'[Measure] ), IF ( SELECTEDVALUE ( 'test'[Measure] ) = "Count" || SELECTEDVALUE ( 'test'[Measure] ) = "Sale", SUM ( 'test'[Value] ), _sale / _count ), SUM ( test[Value] ) + _sale / _count )Best Regards,
Yingjie LiIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.