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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
UlisesCiccola
Helper I
Helper I

How to calculate average time between orders by customer

Hello!

 

I have a table of orders with a timestamp in datetime format as follows:

 

Order Id    Time of the order    customer  

 

1                2020-1-1 00:12:12     1

2               2020-2-3  04:55:05      1

3               2020-3-4   12:30:20    2

4               2020-4-5    00:15:30    3

 

I need to calculate the average time between orders by customers in minutes (or days). How can this be accomplished using dax? 

Imagine I have more customers and more orders. So for instance customer 1 has an average of 2 orders/time difference between their first order and the second one.

4 REPLIES 4
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1609303295093.png

 

amitchandak
Super User
Super User

@UlisesCiccola , as a new column

[Time of the order] - maxx(filter(Table, [Order Id] =earlier([Order Id]) && [Time of the order] <earlier([Time of the order])) ,[Time of the order])

 

as a new measure

[Time of the order] - maxx(filter(allselected(Table), [Order Id] =max([Order Id]) && [Time of the order] <max([Time of the order])) ,[Time of the order])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

@UlisesCiccola Well, you could create a new column and use EARLIER to calculate time between orders. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

Then you could put the average of this column in a visual along with the customer ID.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  what would go in the variable current on this example? The column time of the order? 

 

Thanks in advance!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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