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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tamara_nsb
Helper I
Helper I

Dax for overall average of last value in every groups

Hi Guys, 

I have the following data and I need to display the Average Value of items using only the most recent input for each item and grouped by sortOrder.    

 

 

Date           ItemID    SortOrder   Value    
8/1/202040351.77
8/1/202040311.77
8/1/202042926.1
8/1/2020429311.03
7/1/2020220434.23
7/1/202040311.60
7/1/202041547.87
7/1/202042924.97
7/1/2020429333.03
7/1/2020123218.17
7/1/2020123327
7/1/2020123450.03

 

Expected Results:    I am able to get the count of items with Count ItemID (Distinct)

Sort Order    Average of Value  Number Of Items                   
11.771
212.1352
319.0152
430.713
51.771

 

Please let me know if more information is needed,  I am really stumped.

I can create a measure that will return the last value for each group,  but then how do i get that measure to average by Sort Order

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @tamara_nsb 

Thanks for your sample data and end result first!

Here are the steps you can refer to :
We can create a measure like this:

 

Measure = var _t =ADDCOLUMNS(  SUMMARIZE('Table','Table'[SortOrder],'Table'[ItemID] , "Date" , CALCULATE(MAX('Table'[Date])) )    ,  "value" , var _date=[Date] return CALCULATE( SUM('Table'[Value]),'Table'[Date]=_date)  )
return
AVERAGEX(_t,[value])
 
 
Then we can put it on the visual and we can meet your need:
vyueyunzhmsft_0-1691742619310.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
tamara_nsb
Helper I
Helper I

Thanks for your response, that worked perfectly.    I was on the right track using summarize and max(date) but I was missing the AddColumns which was the step that made the difference.

 

v-yueyunzh-msft
Community Support
Community Support

Hi , @tamara_nsb 

Thanks for your sample data and end result first!

Here are the steps you can refer to :
We can create a measure like this:

 

Measure = var _t =ADDCOLUMNS(  SUMMARIZE('Table','Table'[SortOrder],'Table'[ItemID] , "Date" , CALCULATE(MAX('Table'[Date])) )    ,  "value" , var _date=[Date] return CALCULATE( SUM('Table'[Value]),'Table'[Date]=_date)  )
return
AVERAGEX(_t,[value])
 
 
Then we can put it on the visual and we can meet your need:
vyueyunzhmsft_0-1691742619310.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.