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
WilliamLindley
Frequent Visitor

Average of a measure VAR

Hi,

I have created a measure which returns the difference from the previous row’s value (the moving range)

I then need to take the average of all these values.

It works fine using two measures, however as soon as I declare the first measure (the moving range) as a VAR in the second measure (the average) it returns different values for each row whereas I want the average, ie: the same 1 figure over all the rows.

Please help!!!!

 

 

POWER BI HELP 1.PNG

here are my measures;

 

Moving Range =

VAR EarlierTime = CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALLSELECTED ( 'Table'[Date] ),
'Table'[Date] < SELECTEDVALUE ('Table'[Date] )
)
)
VAR EarlierMeasureValue =
CALCULATE ( SUM('Table'[Value]), 'Table'[Date] = EarlierTime )

VAR Moving_Range =
ABS ( EarlierMeasureValue - SUM('Table'[Value]) )

RETURN
Moving_Range
 
 
 
Average Moving Range = CALCULATE(AVERAGEX(DISTINCT('Table'[Date]),[Moving Range]),ALLSELECTED('Table'[Date]))
 
 
10 REPLIES 10
V-pazhen-msft
Community Support
Community Support

@WilliamLindley 

 

Try use summarized table in your measure something like this:

Measure = AVERAGEX(SUMMARIZE('Table','Table'[column], "ToAverage", [Measure]), [Measure])
 
Best,
Paul

i have added measures.

 

i cannot link to the file and dropbox wont work sorry.

 

@V-pazhen-msft i tried that summarize formula as below, still didnt work

Not Clear what avg you need. I created one. But not sure on expected value.

https://www.dropbox.com/s/1so2a6mvm14sake/MovingAvg.pbix?dl=0

Hi Amit,

 

thanks for your reply, but unfortuntely this isn't what i was looking for.

 

I am needing the 'Average Moving Range' which is 32.42 but with only 1 single measure, not having to create the 'Moving Range' and then another measure to average it.

 

Thanks for your time, if you are able to look again i would be really grateful.

 

cheers

 

@WilliamLindley, check at same like

Like this

 

Moving Range 2 = 

VAR EarlierTime = CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALLSELECTED ( 'Table'[Date] ),
'Table'[Date] < SELECTEDVALUE ('Table'[Date] )
)
)
VAR EarlierMeasureValue =
CALCULATE ( SUM('Table'[Value]), 'Table'[Date] = EarlierTime )

VAR Moving_Range =
ABS ( EarlierMeasureValue - SUM('Table'[Value]) )

RETURN
 CALCULATE(AVERAGEX(ALLSELECTED('Table'[Date]),Moving_Range))

 

thanks, but still no.

as you can see this simply gives the moving range, i need the average of 32.42 in all rows, (like is showing in the 'average moving range' column

 

Capture.PNG

 
 
 
 
az38
Community Champion
Community Champion

Hi @WilliamLindley 

did you try AVERAGEX() function? https://docs.microsoft.com/en-us/dax/averagex-function-dax 

like 

= AVERAGEX(Table, Table[YourMeasure])

  


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi thanks for your reply. Yes I have tried that it just returns the same figure for the average at it does for the actual moving range, eg; the average for that row not all the rows. Calculate / all doesn’t work either once declared as a variable

@WilliamLindley 

so, show us your measure statement and data example


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hi @WilliamLindley 

Can you provide a sample pbix file and the expected results, makes trying to create the formula a lot easier



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


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.