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
ryan_mayu
Super User
6 years agoplease try to create three measures
average type a = AVERAGEX(FILTER('Table','Table'[TYPE]="A"),'Table'[COST])
average type b = AVERAGEX(FILTER('Table','Table'[TYPE]="B"),'Table'[COST])
dif = [average type a]-[average type b]emionline
6 years agoFrequent Visitor
Thank you very much for the answer, it only remains to solve the measure that adds up the total averages.
The final result should give -75
That is the measure that I cannot solve and that I need to analyze with any other dimension of the table