March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi!
I am having troubles with calculating the maximum difference between two consecutive purchases for each customer. Note that this is not the same as date difference between first and last purchase.
I have two tables (Purchase_table and Customer_table) which are related via CustomerID. In the Purchase_table the same CustomerID's are existing multiple times. As shown in the example pictures, I would like to calculate values for the column Max_diff_betw_purch. In the example I manually inputted value "8" for customer "1001", since it is the date difference between his second and third purchase, which is bigger than the difference between his first and second purchase.
Any help with this? I would prefer to do this with Power BI Desktop in data mode by adding a new column (Max_diff_betw_purch).
Sincerely,
L
Solved! Go to Solution.
You can use this column in the Customers Table
Max_diff_between_Purchase = VAR temp = CALCULATETABLE ( VALUES ( Purchase_table[PurchaseDate] ) ) VAR temp1 = ADDCOLUMNS ( temp, "Days", DATEDIFF ( [PurchaseDate], MINX ( FILTER ( temp, [PurchaseDate] > EARLIER ( [PurchaseDate] ) ), [PurchaseDate] ), DAY ) ) RETURN MAXX ( temp1, [Days] )
Please see attached file with your sample data
You can use this column in the Customers Table
Max_diff_between_Purchase = VAR temp = CALCULATETABLE ( VALUES ( Purchase_table[PurchaseDate] ) ) VAR temp1 = ADDCOLUMNS ( temp, "Days", DATEDIFF ( [PurchaseDate], MINX ( FILTER ( temp, [PurchaseDate] > EARLIER ( [PurchaseDate] ) ), [PurchaseDate] ), DAY ) ) RETURN MAXX ( temp1, [Days] )
Perfect, thank you Zubair! Your column worked like a charm.
I really appreciate the help!
-L
Please see attached file with your sample data
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
146 | |
97 | |
79 | |
69 |