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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
pranshu_07
Frequent Visitor

DAX for the average of 5 latest orders by the retailers based on the Order dates.

Hello all,

I've to calculate the average of the last 5 orders placed by the retailers. When I use quick measure (average per category) it shows right result for the retailers <=5 but for the retailers above 5 orders it calculate the total order average. 

Average_order = AVERAGEX ( KEEPFILTERS(VALUES('Catalog Line Item'[Order_Date])),
    CALCULATE(SUM('Catalog Line Item'[Order_value]))
)
I modified the dax for the last 5 result using top N function,
Average_Order =
AVERAGEX(
KEEPFILTERS(TOPN(5,'Catalog Line Item','Catalog Line Item'[Order_Date].[Date],DESC)),
CALCULATE(SUM('Catalog Line Item'[Order_value]))
)
The results were wrong,
Kindly request your assistance.
1 ACCEPTED SOLUTION

@achanikya , Please, check my code again

rankx(filter(Table, [retailer_ID] = earlier([retailer_ID] )), [Order_Date],,desc,dense)

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

4 REPLIES 4
amitchandak
Super User
Super User

@pranshu_07 , if this not based on selected date, then you can have column rank

 

example

rankx(filter(Table, [retailer_ID] = earlier([retailer_ID] )), [Order_Date],,desc,dense)

 

and filter <=5

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

Hi I Need Last 5 order Averge Sales on Outlet based . SO can you elaborate on the above DAX that after alocatting rank to the date of sale how can I calculate the average.

for eg: Condition 1: If a retailer buy 3000 rs. worth of item only 3 times this year than the average will be 3000/3=1000.

but if the other retailer had bought 3000rs. worth items 5 times this year then it should be 600.

and if he bought more than 5 times than also 600.

the sales may be continous or in a random manner like (jan, march,august) 

@achanikya , Please, check my code again

rankx(filter(Table, [retailer_ID] = earlier([retailer_ID] )), [Order_Date],,desc,dense)

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

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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