Forum Discussion

emionline's avatar
emionline
Frequent Visitor
6 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    6 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