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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ljmanayon
Frequent Visitor

Calculate the customer time interval in a row

Hi All,

 

Good day!

 

I've been searching for a solution on this problem for a couple of days now but I can't seem find the right solutions. I'm hoping that someone can help me.

 

I want to to calculate the time interval in minutes between customers with remarks as "New Entry" (new customer who comes in to the branch and get his/her queuing number). Meaning the time interval between the first customer and the 2nd customer, 2nd customer and 3rd customer, etc...

 

Data Sample:

 

Branch CodeDateTimeProductService IDRemarks
DVS017/1/218:00:00 AMMoneyM001New Entry
DVS017/1/218:09:21 AMMoneyM001Serving
DVS017/1/218:12:00 AMMoneyM001Done
DVS017/1/218:10:00 AMCargoC001New Entry
DVS017/1/218:10:00 AMCargoC001Serving
DVS017/1/218:15:12 AMCargoC001Done
DVS017/1/219:00:00 AMBillsB001New Entry
DVS017/1/219:10:00 AMBillsB001Serving
DVS017/1/219:12:00 AMBillsB001 Done

 

The results that I want:

Branch CodeDateTimeProductService IDRemarksCustomer Interval
DVS017/1/218:00:00 AMMoneyM001New Entry0
DVS017/1/218:09:21 AMMoneyM001Serving 
DVS017/1/218:12:00 AMMoneyM001Done 
DVS017/1/218:10:00 AMCargoC001New Entry10mins
DVS017/1/218:10:00 AMCargoC001Serving 
DVS017/1/218:15:12 AMCargoC001Done 
DVS017/1/219:00:00 AMBillsB001New Entry50mins
DVS017/1/219:10:00 AMBillsB001Serving 
DVS017/1/219:12:00 AMBillsB001 Done 

 

To further explain my table above. It means, the 1st customer get his queue number at 8:00AM with remarks as "new entry", then a 2nd customer comes in at 8:10AM, so that's a 10mins interval from the 1st customer. Then a 3rd customer comes in at 9:00AM, so that's a 50mins interval from the 2nd customer.

 

The remarks "Serving" pertains to the time the customer was served or called and "Done" means transactions was completed. Just in case you want to know.

 

I tried this solution https://community.powerbi.com/t5/Desktop/Time-difference-between-next-row/m-p/338621, but it doesn't work for me and I got the same problem as posted there.

 

Any help will be greatly appreciated.

 

Thank you in advance.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@ljmanayon , Try a new column like

 

new column =
var _1 = maxx(filter(Table, [Branch] =earlier([Branch]) && [Date] = earlier([Date]) && [Time] <earlier([Time]) && [Remarks] = "New Entry"), [Time])
return
if( [Remarks] = "New Entry" , datediff(_1,[time], minute))

 

 

or measure like

 

new measure =
var _1 = maxx(filter(allselected(Table), [Branch] =max([Branch]) && [Date] = max([Date]) && [Time] <max([Time]) && [Remarks] = "New Entry"), [Time])
return
if( max([Remarks]) = "New Entry" , datediff(_1,max([time]), minute))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@ljmanayon , Try a new column like

 

new column =
var _1 = maxx(filter(Table, [Branch] =earlier([Branch]) && [Date] = earlier([Date]) && [Time] <earlier([Time]) && [Remarks] = "New Entry"), [Time])
return
if( [Remarks] = "New Entry" , datediff(_1,[time], minute))

 

 

or measure like

 

new measure =
var _1 = maxx(filter(allselected(Table), [Branch] =max([Branch]) && [Date] = max([Date]) && [Time] <max([Time]) && [Remarks] = "New Entry"), [Time])
return
if( max([Remarks]) = "New Entry" , datediff(_1,max([time]), minute))

Hi Sir @amitchandak ,

 

Thank you very much for your help. I really do appreciate your help.

Your formula for "new column" I think it works. However, when I tried the measure, it gives me nothing, it's blank.

 

I temporarily named my column, "Customer Interval" and "Interval" for measure, just a sample name to test the formula.

 

ljmanayon_0-1627041002906.png

This ones work for creating a column

Customer Interval =
var Diff =
MAXX(FILTER('QMS Data',[Branch]
=EARLIER([Branch]) && [Date] = EARLIER([Date]) && [Time]
< EARLIER([Time]) && [Remarks] = "New Entry"),[Time])
RETURN
IF([Remarks] = "New Entry",
DATEDIFF(Diff, [Time], MINUTE))
 
But for the measure it doesn't,
 
Interval =
var Diff =
MAXX(FILTER(ALLSELECTED('QMS Data'),[Branch]
=MAX([Branch]) && [Date] = MAX([Date]) && [Time]
< MAX([Time]) && [Remarks] = "New Entry"),[Time])
RETURN
IF(MAX('QMS Data'[Remarks]) = "New Entry",
DATEDIFF(Diff, MAX('QMS Data'[Time]), MINUTE))
 
I tried to use this, but it gives me a syntax error on the column name [Remarks] and [Time] with bold font.
 
Interval =
var Diff =
MAXX(FILTER(ALLSELECTED('QMS Data'),[Branch]
=MAX([Branch]) && [Date] = MAX([Date]) && [Time]
< MAX([Time]) && [Remarks] = "New Entry"),[Time])
RETURN
IF(MAX([Remarks]) = "New Entry",
DATEDIFF(Diff, MAX([Time]), MINUTE)) 
 
I'd prefer to use a measure to save some memory since I have hundreds of thousounds of data and counting.
 
I can't figure out where did I go wrong.
 
 
Regards.
 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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