Forum Discussion
emionline
6 years agoFrequent Visitor
Average by category and type
Good afternoon I have a problem that I cannot solve I have a table that has different types and categories of product and I want to calculate an indicator by adding the differences that exist between...
- Anonymous6 years ago
Hi emionline ,
I'm so sorry for my late reply.
I modified the previous formula, you could use the following formula:
averageA = CALCULATE ( AVERAGE ( 'Average table'[Cost] ), FILTER ( ALL ( 'Average table' ), 'Average table'[Category] = MAX ( 'Average table'[Category] ) && [Type] = "A" ) )averageB = CALCULATE ( AVERAGE ( 'Average table'[Cost] ), FILTER ( ALL ( 'Average table' ), 'Average table'[Category] = MAX ( 'Average table'[Category] ) && [Type] = "B" ) )Diff = 'Average table'[averageB] - 'Average table'[averageA]sumDiff = VAR _diff = [averageB]- [averageA] Var _a = SUMX(ADDCOLUMNS(VALUES('Average table'[Category]),"sumDiff",CALCULATE([Diff],ALLEXCEPT('Average table','Average table'[Category]))),[sumDiff]) return IF(HASONEVALUE('Average table'[Category]),_diff, _a)My visualization looks like this:
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin
Anonymous
6 years agoNot applicable
Hi emionline ,
I'm so sorry for my late reply.
I modified the previous formula, you could use the following formula:
averageA =
CALCULATE (
AVERAGE ( 'Average table'[Cost] ),
FILTER (
ALL ( 'Average table' ),
'Average table'[Category] = MAX ( 'Average table'[Category] )
&& [Type] = "A"
)
)averageB =
CALCULATE (
AVERAGE ( 'Average table'[Cost] ),
FILTER (
ALL ( 'Average table' ),
'Average table'[Category] = MAX ( 'Average table'[Category] )
&& [Type] = "B"
)
)Diff =
'Average table'[averageB] - 'Average table'[averageA]sumDiff =
VAR _diff = [averageB]- [averageA]
Var _a = SUMX(ADDCOLUMNS(VALUES('Average table'[Category]),"sumDiff",CALCULATE([Diff],ALLEXCEPT('Average table','Average table'[Category]))),[sumDiff])
return
IF(HASONEVALUE('Average table'[Category]),_diff, _a)My visualization looks like this:
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.
Best Regards,
Eyelyn Qin