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.
Hello,
I am trying to calculate the turn around time for a ticketing system with working hours between 8AM-1AM Monday-Friday. Orders can be placed by customers anytime, so, if an order is placed outside of working hours, the time difference will calculate beginning the next working day at 8AM.
Another challenge is that MessageSentTimeLocal can be outside of working hours as well, but the turn around time should be calculated up until the end of the working day at 1AM.
Some sample data below:
For orders like Order#35812, the TAT should be about 5.5 hours since MessageTimeLocal should technically be treated as 1AM as it is outside of working hours.
If the MessageSentTimeLocal is after a couple of days from order date, the TAT should still only account for the working hours between 8AM-1AM.
If an order and MessageSentTimeLocal are both not within working hours, the TAT should be 0.
Help will be greatly appreciated!
Solved! Go to Solution.
Hi @mpalha04,
You could modify the former formula with this:
Hours = var a= IF([OrderedDateLocal]>=[Column],[OrderedDateLocal],[Column]) var b= IF([MessageSentTimeLocal]<=[Column2],[MessageSentTimeLocal],[Column2]) return IF(DATEDIFF(a,b,MINUTE)/60<0,DATEDIFF('Table1'[OrderedDateLocal],[MessageSentTimeLocal],MINUTE)/60,DATEDIFF(a,b,MINUTE)/60)+IF(DATEDIFF([Column2]+(7/24),[MessageSentTimeLocal],MINUTE)/60>0,DATEDIFF([Column2]+(7/24),[MessageSentTimeLocal],MINUTE)/60,0)
You can also download the PBIX file to have a view.
Regards,
Daniel He
Hi @mpalha04,
Based on my test, you could refer to below steps:
Sample data:
Create three calculated columns:
Column = SUBSTITUTE('Table1'[OrderedDateLocal],RIGHT('Table1'[OrderedDateLocal],11)," 8:00:00 AM")
Column2 = (SUBSTITUTE('Table1'[MessageSentTimeLocal],RIGHT('Table1'[MessageSentTimeLocal],11)," 1:00:00 AM"))
Hours = var a= IF([OrderedDateLocal]>=[Column],[OrderedDateLocal],[Column]) var b= IF([MessageSentTimeLocal]<=[Column2],[MessageSentTimeLocal],[Column2]) return IF(DATEDIFF(a,b,MINUTE)/60<0,DATEDIFF('Table1'[OrderedDateLocal],[MessageSentTimeLocal],MINUTE)/60,DATEDIFF(a,b,MINUTE)/60)
Now you could get the correct result.
You can also download the PBIX file to have a view.
Regards,
Daniel He
Hi Daniel,
This is great, but there are some cases that need to be resolved:
If the order is placed and MessageSentTimeLocal is the next day. Refer Order# 35386 - the hours should be about 20 hours since working hours are 8AM-1AM :
If the order is placed outside working hours and MessageSentTime local is outside of working hours. Refer to Order#s 35412, 35413 below - the hours should be 0.
If an order is placed on the weekend, the hours should start calculating beginning work hours. Please refer to all the data below: The orders highlighted should be about 10mins. Although August 4 is a Saturday, it before 1AM so the working hours from Friday carries over. No working hours should be calculated on Saturday and Sunday... working hours would begin calculating the following Monday at 8AM.
Hi @mpalha04,
Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?
Regards,
Daniel He
Hi @mpalha04,
You could modify the former formula with this:
Hours = var a= IF([OrderedDateLocal]>=[Column],[OrderedDateLocal],[Column]) var b= IF([MessageSentTimeLocal]<=[Column2],[MessageSentTimeLocal],[Column2]) return IF(DATEDIFF(a,b,MINUTE)/60<0,DATEDIFF('Table1'[OrderedDateLocal],[MessageSentTimeLocal],MINUTE)/60,DATEDIFF(a,b,MINUTE)/60)+IF(DATEDIFF([Column2]+(7/24),[MessageSentTimeLocal],MINUTE)/60>0,DATEDIFF([Column2]+(7/24),[MessageSentTimeLocal],MINUTE)/60,0)
You can also download the PBIX file to have a view.
Regards,
Daniel He
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
77 | |
74 | |
49 |
User | Count |
---|---|
146 | |
108 | |
106 | |
90 | |
62 |