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

Calculating average values in groups of 3 on most recent entries

Hello,

 

at this moment I have a table which looks similar to this:

 

Date               Liters             Group          

2022-08-30    65.22             1                    

2022-08-28    33.12             1                    

2022-08-27    42.29             1                    

2022-08-26    43.69             1                   

2022-08-25    78.22             1                   

2022-08-23    28.79             1                    

2022-08-20    46.58             1                    

2022-08-19    45.27             1                    

2022-08-18    19.62             1   

 

In my table I filter out 36 most recent records for each group and I am looking for a way to measure average values in 'Liters' column in groups of 3, for instance when we take first 3 rows: (65.22+33.12+42.29)/3=46.88. That way I would get 12 different values from 36 rows. Another problem with this table is that the values are taken from sharepoint and are always receiving new records, but this statistic needs to be done on 36 most recent entries. Filtering by hand is very time consuming, so I am looking for ways to make this automatic.  If anyone has any ideas, how this can be done, your help would be appreaciated.  

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@RSip , Create a column rank first

 

Rank = rankx(filter(Table, [group] = earlier([Group]) ), [Date], , desc, dense)

 

now you can use filter rank <=3 in measure

 

or create another column

 

Sum= AverageX(filter(Table, [group] = earlier([Group]) && [Rank] <=3),[Liters] )

 

 

Or create measure like

cnt = countx(filter(allselected(Table),[group] = max([Group])), [Date]) 

 

Sum= AverageX(filter(Values(Table[group]), [cnt ]<=3),calculate(Sum([Liters])) )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@RSip , Create a column rank first

 

Rank = rankx(filter(Table, [group] = earlier([Group]) ), [Date], , desc, dense)

 

now you can use filter rank <=3 in measure

 

or create another column

 

Sum= AverageX(filter(Table, [group] = earlier([Group]) && [Rank] <=3),[Liters] )

 

 

Or create measure like

cnt = countx(filter(allselected(Table),[group] = max([Group])), [Date]) 

 

Sum= AverageX(filter(Values(Table[group]), [cnt ]<=3),calculate(Sum([Liters])) )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you very much. It solved the problem.

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!

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.