Excel complicated formula for a user form - vba

Some of my colleagues attend conferences, meetings and workshops in various cities.
An example of a made up itinerary is shown below
The itinerary includes stopovers and each location is marked by a trip number. (A:15 to A:22)
I am working on a user form which would give me the time spent in hours and minutes from the departure to the arrival time for each trip number. Note that some trips include a stopover which is why there are three trip number entries for number 1 (trip to Frankfurt via Paris)
I know that the overall time spent for all these trips is 185 hours and 45 minutes as stated in L:23.
In red, along raw 23 there are five formulas as follows:
C:23 shows 24/06/2016 which is =C17
D:23 shows 19:15 which is =D17
H:23 shows 16/01/2016 which is =LOOKUP(2,1/(H17:H22<>""),H17:H22) it picks up the last date inserted between H17:H22
J:23 shows 13:00 which is =LOOKUP(2,1/(J17:J22<>""),J17:J22) it picks up the last time value inserted between J17:J22
L:23 shows 185:45 hours and minutes. It is the difference between the departure date and time of the first and the arrival date and time of the last trip. (Overall time in hours and minutes) =MAX(0,(H23+J23)-(C23+D23))
I need a way to work out the total time of 185:45 broken down between various business trip numbers in C:26 to C:29. Note that trips will always be shown in a logical order i.e. 1,2,3 but the amount of legs per trip will vary depending on stop overs. The minimum amount of trips is 1 and the maximum amount of trips is 4.
Thanking you in advance
Abe

Try this:
=TEXT(MAX(IF($A$17:$A$22=A26,$I$17:$I$22+$J$17:$J$22))-MIN(IF($A$17:$A$22=A26,$C$17:$C$22+$D$17:$D$22)),"[hh]:mm")
It is an array formula and must be confirmed with Ctrl-Shift-Enter. Put in C26, hit Ctrl-Shift-Enter then copy down.
Edit: As per OP's comments, what was wanted was the total of time from beginning of leg to the beginning of the next leg. So the formula was changed to:
=IF(MIN(IF($A$17:$A$22=A26+1,$C$17:$C$22+$D$17:$D$22))=0,MAX(IF($A$17:$A$22=A26,$I$17:$I$22+$J$17:$J$22)),MIN(IF($A$17:$A$22=A26+1,$C$17:$C$22+$D$17:$D$22)))-MIN(IF($A$17:$A$22=A26,$C$17:$C$22+$D$17:$D$22))
This is still an array formula. It needs to be confirmed by hitting Ctrl-Shift-Enter. Then copied down.

Related

Postgres SQL count events with minimum and maximum time gap

I have a Postgres database table of 'events' (i.e. rows with a timestamp column). I want to count the number of events that are separated by more than a specified minimum time gap and by less than or equal to a specified maximum time gap.
For example, if there is an event on 6 consecutive days but I specify a minimum time gap of 2 days, I only want to register a count of 1 for those 6 events.
At the same time, if I specify a maximum time gap of 30 days, if two events are 30 days apart I want to register a count of 2 for the pair, but if they are 31 days apart I want to register a count of 0.
The accepted answer to the following post gives a method for counting events and satisfying the 'maximum gap' requirement using the Postgres generate_series function:
Best way to count rows by arbitrary time intervals
Maybe it's possible to modify the suggested solution to also satisfy the 'minimum gap' requirement. Can anyone advise on how I can accomplish this? Thanks.

SUM of last 24 hour scores within a specific range in a sorted set (Redis)

Is there a way to calculate the SUM of scores saved under 24 hour respecting performance of the Redis server ? (For around 1Million new rows added per day)
What is the right format to use in order to store timestamp and score of users using sorted sets ?
Actually I am using this command:
ZADD allscores 1570658561 20
As score, it is the actual time in seconds ... and other field is the real score.
But, there is a problem here ! When another user get the same score (20), it is not added since it's already present - Any solution for this problem ?
I am thinking to use a LUA script, but there is 2 headaches:
The LUA script will block other commands from working until it is finished the job (Which is not a good practice for my case since the script have to work 24/24 7/7 meanwhile many users have to fetch datas in the same time from the Redis cache server like users scores, history infos ect.) - Plus, the LUA script have to deal each time with many records saved each day inside a specific key - So, while the Lua script is working, users can't fetch datas ... knowing that the Lua script will work in loop all time.
Second, it is related to the first problem that do not let me store same score if I use timestamp as score in the command so I can return 24 hour datas.
If you are in my case, how will you deal with this ? Thanks
Considering that the data is needed for last 24 hours(Sliding window) and the number of rows possible is 1 million. We cannot use sorted set data structure to compute sum with high performance.
High performance design and also solving your duplicate score issue:
Instead with a little decision on the accuracy, you can have a highly performant system by crunching the data within a window.
Sample Input data:
input 1: user 1 wants to add time: 11:10:01 score: 20
input 2: user 2 wants to add time: 11:11:02 score: 20
input 3: user 1 wants to add time: 11:17:04 score: 50
You can have 1 minute, 5 minutes or 1 hour accuracy and decide window based on that.
If you accept an approximation of 1 hour data, you can have this while insertion,
for input 1 :
INCRBY SCORES_11_hour 20
for input 2:
INCRBY SCORES_11_hour 20
for input 3:
INCRBY SCORES_11_hour 20
To get the data for last 24 hours, you need to sum up only 24 hourly keys.
MGET SCORES_previous_day_12_hour SCORES_previous_day_13_hour SCORES_previous_day_14_hour .... SCORES_current_day_10_hour SCORES_current_day_11_hour
If you accept an approximation of 5 minutes, you can have this while insertion, along with incrementing the hourly keys, you need to store the 5 minute window data.
for input 1 :
INCRBY SCORES_11_hour 20
INCRBY SCORES_11_hour_00_minutes 20
for input 2:
INCRBY SCORES_11_hour 20
INCRBY SCORES_11_hour_00_minutes 20
for input 3:
INCRBY SCORES_11_hour 20
INCRBY SCORES_11_hour_05_minutes 20
To get the data for last 24 hours, you need to sum up only 23 hour keys(whole hours data) + 12 five minute window keys
If the time added is based on the current time, you can optimize it further. (Assuming that if it is 11th hour and the data for 10th, 9th and the previous hours wont change at all).
As you told it is going to be 24/7, we can use some computed values from the previous iterations too.
Say it is computed on 11th hour, you would've got the values for past 24 hours.
If it is again computed on 12th hour, you can reuse the sum for 22 intermediate hours whose data is unchanged and get only the missing 2 hours data from redis.
Similarly further optimisations can be applied based on your need.

Calculate average VBA from dynamic table

I ve a table on Excel with the week number and the weight (in Kg.)
Somebody can insert his weight every day during a week or just once or not at all. I can't manage that.
Then my table can literally change. from zero to 7 even more lines a week (like the yellow side of the image).
What I wanna do is to calculate the weight average per week. and then I will have one line for each week, when i got at least one weight (sometimes I won't have any line). We can have week without any weight so then I don't want this line at all. We can also easily have a weight for the week 2 but between the weeks 5 and 6 in the yellow table. That would happen if someone insert his weight after others.
How can I say this two weeks are similar, so we calculate the average for this two weight ?
I hope it's enough clear with this picture
Use formula below in Column C to calculate average(assume Week in column A and Weight in column B)
=AVERAGEIF(A:A,A2,B:B)
Average Column Copy->PasteSpecial value only,
then Remove Duplicates base on Week and the new Average Column

Need NetSuite search formula to display employee time records by projects (in rows) and day of week (in columns)

I'm trying to create a NetSuite Time search that emulates the chart style display on an employee's weekly time record, with projects listed in rows and days of the week listed in columns, with totals by day and by project. The goal is to have a search auto filtered by "Last Week" that can be used with a drop down selector filter for employees. I know there are better ways, but this is a very specific demand from someone above who believes the NS time record is a "query" and wants it to act like one.
I'm good with NS searches but know almost next to nothing about coding. I tried some basic sum formulas using CASE WHEN but am having 2 issues:
1) Can't figure out how to get CASE WHEN to sort by the weekday output from DAY of the {date} and subsequently total the hours.
2) Not sure how to total hh:mm formatted time in searches, and can't figure out what the system name of the "Duration (Decimal)" field is.
Just need one line of a sum formula to total time data from one day of the week, and a way to solve the hh:mm issue and I am good to go from there.
CASE WHEN to_char({date}, 'D') LIKE 1 THEN {durationdecimal} ELSE 0 END
SUN = 1, MON = 2, etc.

In Crystal Report print only first record in group and leave it summable

I have a table that lists every task an operator completed during a day. This is gathered by a Shop Floor Control program. There is also a column that has the total hours worked that day, this field comes from their time punches. The table looks something like this:
Operator 1 Bestupid 0.5 8 5/12/1986
Operator 1 BeProductive 0.1 8 5/12/1986
Operator 1 Bestupidagain 3.2 8 5/12/1986
Operator 1 Belazy 0.7 8 5/13/1986
Operator 2 BetheBest 1.7 9.25 5/12/1986
I am trying to get an efficiency out of this by summing the process hours and comparing it to the hours worked. The problem is that when I do any kind of summary on the hours worked column it sums EVERY DETAIL LINE.
I have tried:
If Previous (groupingfield) = (groupingfield) Then
HoursWorked = 0
Else
HoursWorked = HoursWorked
I have tried a global three formula trick, but neither of the above leave me with a summable field, I get "A summary has been specified on a non-recurring field"
I currently use a global variable, reset in the group header, but not WhilePrintinganything. However it is missing some records and upon occasion I will get two hoursworked > 0 in the same group :(
Any ideas?
I just want to clarify, I have three groups:
Groups: Work Center --> Operator --> Date
I can summarize the process hours across any group and that's fine. However, the hours worked prints on every detail line even though it really should only print once per Date. Therefore when I summarize the Hours Worked for an operator the total is WAY off because it is adding up 8hours for each entry instead of 8 hours for each day.
Try grouping by the operators. Then create a running total for the process hours that sum for each record and reset on change of group. In the group footer you can display the running total and any other stats for that operator you care to.
Try another running total for the daily hours but pick maximum as the type of summary. Since all the records for the day will have the same hours work the maximum will be correct. Reset with the change of the date group and you should be good to go.