The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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.
@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])
@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.
@Greg_Deckler what would go in the variable current on this example? The column time of the order?
Thanks in advance!
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |
User | Count |
---|---|
27 | |
19 | |
13 | |
9 | |
5 |