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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sebasjun
Helper I
Helper I

SUMX with calculate average

Hello

 

I need apply this function 

 

Formula.png

 

 

I created a simple datatable

 

s.png

 

 

AVGx = AVERAGE(Table1[x]) 

Measure Manual = SUMX(Table1; Table1[x] - 14)

Measure Calc = SUMX(Table1;(Table1[x] - [AVGx]))

 

Mesaure Manual is my desired result and Measure Calc is my automated measure

 

The problem is in Measure Calc this  caculate the average per each row and is the same wth x and the result is 0 normal!, i need to calculalte the average total in the context filter (Cliente = C1) --> 14  

 

Thanks

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

Hello @sebasjun

Try this - storing the average in a variable. Previously when the [AVGx] measure was computed in the context of each row, context transition meant that it was just averaging the value on that row.

Measure Calc =
VAR Avg = [AVGx]
RETURN
  SUMX ( Table1; ( Table1[x] - Avg ) )

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

Stachu
Community Champion
Community Champion

I think the average has to be either with ALL or ALLSELECTED

AVGx:=CALCULATE(AVERAGE(Table1[x]),ALLSELECTED(Table1[x]))

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

5 REPLIES 5
v-yuta-msft
Community Support
Community Support

Hi sebasjun,

 

Change measure [AVGx] to a calculate column [AVGx Column] them modify [Measure Calc] using DAX like this:

 

Measure Calc = VAR XXX = MAX(Table1[AVGx Column]) RETURN SUMX ( Table1, ( Table1[x] - XXX ) ) 

The result is as below:

1.PNG 

Regards,

Jimmy Tao

OwenAuger
Super User
Super User

Hello @sebasjun

Try this - storing the average in a variable. Previously when the [AVGx] measure was computed in the context of each row, context transition meant that it was just averaging the value on that row.

Measure Calc =
VAR Avg = [AVGx]
RETURN
  SUMX ( Table1; ( Table1[x] - Avg ) )

Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hello

 

Thanks for you reply, I try and is 0 

 

I attached the file if you can help me  File

Stachu
Community Champion
Community Champion

I think the average has to be either with ALL or ALLSELECTED

AVGx:=CALCULATE(AVERAGE(Table1[x]),ALLSELECTED(Table1[x]))

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

This measure gets the same results as your manual process

 

Measure =
SUM ( Table1[x] ) - CALCULATE ( [AVGx], ALLSELECTED ( Table1 ) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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