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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
juli__sia123412
Frequent Visitor

Average days between orders

Question is simple, but I'm totally lost.

I have the next data:

buyerID - OrderId - Rank (1,2,3...meant order index)  - Purchase date 

123       - 123347      - 1                                                 - 1/1/2019

123       - 123354      - 2                                                 - 1/3/2019

143       - 145347      - 1                                                 - 1/2/2019

145       - 168437      - 1                                                 - 1/1/2019

 

I need to calculate AVG numbers of days between orders using measure

Thanks!

1 ACCEPTED SOLUTION
vanessafvg
Super User
Super User

@juli__sia123412 

 

you would first need to create a calculated column that gets the difference in days between orders

 

DateDiff Previous TransactiondDate =
DATEDIFF(
CALCULATE(
max(Table2[Purchase date])
,FILTER(
ALL('Table2')
,Table2[buyerID] = EARLIER(Table2[buyerID]) && 'Table2'[Purchase date] < EARLIER(Table2[Purchase date]) )), Table2[Purchase date], day)
 
then you can do an avg on that difference with a calculated measure
 
avg = CALCULATE(AVERAGE(Table2[DateDiff Previous TransactiondDate]))
 
 




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
vanessafvg
Super User
Super User

@juli__sia123412 

 

you would first need to create a calculated column that gets the difference in days between orders

 

DateDiff Previous TransactiondDate =
DATEDIFF(
CALCULATE(
max(Table2[Purchase date])
,FILTER(
ALL('Table2')
,Table2[buyerID] = EARLIER(Table2[buyerID]) && 'Table2'[Purchase date] < EARLIER(Table2[Purchase date]) )), Table2[Purchase date], day)
 
then you can do an avg on that difference with a calculated measure
 
avg = CALCULATE(AVERAGE(Table2[DateDiff Previous TransactiondDate]))
 
 




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Hi @vanessafvg 

 

Please note (Earlier) is not supported by DAX , you have to find alternative solution.

 

THNX 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.