Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Delta vs AVG for each row

Hi guys,

I am trying to understand how DAX works, still fighting with that (I am not strong in contexts but I understand it little bit so please take patient ) I have following table

CharValueAvg per group
A12
A32
B25
B85
C150
C9950

 

And my goal is to get new column which will compare current value vs avg for current group (see latest column in right)

 

CharValueAvg per groupDelta from average per group
A12-1
A321
B25-3
B853
C150-49
C995040

 

I tried to use "DELTA = sumx(Avg per group - Values(Value))", context is empty, because it should be evaluated against table above.., I understand that some row context should be used to iterate calculation for each row, but dont t know the formula..

 

any ideas how to fix it and why it is not working?

 

thank you in advance

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    Is your requirement to create measures to get your expected results?

    The Table data is shown below:

    Use the following DAX expression to create measures

    AVG PER GROUP = CALCULATE(AVERAGE('Table'[Value]),ALL('Table'[Value]))
    DELTA = SUMX(VALUES('Table'[Value]),[Value]) - [AVG PER GROUP]

    Final output

    If I understand wrongly, please correct me.

     

    Best Regards,
    Wenbin Zhou
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Regarding your question, it seems that you want to create a calculated column. A calculated column is a row context.You just need to use the following expression.The measure is the filter context.

     

    The following expression means that the operation '[Value] - [Avg per group]' is performed on each row.(Since calculated columns are row context, they all represent values ​​in the same row)

    Column = [Value] - [Avg per group]

    You also used the 'SUMX' function, whose first argument is a table.

     

    Best Regards,
    Wenbin Zhou
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Anonymous ,

      thanks for reply, but my AVG PER GROUP column is already calculated by DAX πŸ™‚ thefore DAX measure for this calculation, sorry if it was confusing

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

        Is your requirement to create measures to get your expected results?

        The Table data is shown below:

        Use the following DAX expression to create measures

        AVG PER GROUP = CALCULATE(AVERAGE('Table'[Value]),ALL('Table'[Value]))
        DELTA = SUMX(VALUES('Table'[Value]),[Value]) - [AVG PER GROUP]

        Final output

        If I understand wrongly, please correct me.

         

        Best Regards,
        Wenbin Zhou
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.