Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Petr__
Helper III
Helper III

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

1 ACCEPTED SOLUTION

Hi @Petr__ ,

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

The Table data is shown below:

vzhouwenmsft_0-1719991830571.png

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

vzhouwenmsft_1-1719991890100.png

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.

View solution in original post

5 REPLIES 5
v-zhouwen-msft
Community Support
Community Support

Hi @Petr__ ,

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]

vzhouwenmsft_0-1719970062051.png

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

vzhouwenmsft_1-1719970165018.png

 

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.

Hello @v-zhouwen-msft ,

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

Hi @Petr__ ,

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

The Table data is shown below:

vzhouwenmsft_0-1719991830571.png

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

vzhouwenmsft_1-1719991890100.png

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.

Hello @v-zhouwen-msft ,
thanks for it 🙂
just question, why you used VALUES ?? I tried it as well but didn't help

Hi @Petr__ ,

I'm just modifying the expression you provided, that's why I'm using the VALUES function.

vzhouwenmsft_0-1720141445639.png

As I mentioned before, the first argument to the SUMX function needs to be a table.

vzhouwenmsft_0-1720141727271.png

VALUES is a table function that returns a table. So it can be used as the first argument of the SUMX function.

vzhouwenmsft_1-1720141558606.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.