简体   繁体   中英

How do I calculate average tons per hour by driver in Google Sheets?

https://docs.google.com/spreadsheets/d/1SiUfqrJNHPAYjibeNBdzWQEcuzka5srf7mSHAv_bn5k/edit?usp=sharing

What would a formula look like to calculate the average tons per hour by driver in this example spreadsheet? Correcting for long times or even days between loads.

We're being charged on an hourly basis for freight so I'd like to figure out which drivers are the most efficient.

It's been tricky because the only concrete source of information we have is the scale tickets. So if they only do a single load in a day or go several hours between loads then the data would be skewed if you use a simple metric like time elapsed.

Also, I'll need the time elapsed between rows (not just the difference between Time In and Time Out) unless that time is > 1.5 hours. So something like:

=(TIMEVALUE(E3)-TIMEVALUE(D2))*24

...With some added logic to not include anything over 1.5 hours.

If a pivot table would be better than a lengthy formula, that's fine with me.

Here's an example for some added context: Driver Cody goes to Farm Nic to receive a load of hay, then comes back to the weigh station (Ticket, Time In, Gross are then determined), dumps the load, comes back to weigh again empty (Tare, Net, and Time Out are determined here), and goes back to Farm Nic until all the hay is harvested. Then it's on to Farm Zach and Farm Williams to repeat the process. There are several Drivers going at a time, which can be seen if the spreadsheet is sorted by Ticket. My goal is to figure out how many Tons each driver delivers per hour. The time elapsed would include the time between Tickets, because Time In and Time Out just show the time elapsed between coming in with a load of hay and leaving to go back to the field. To get a true measure of tons delivered per hour, you'd need to include the time between tickets, but also remove any instance where that time is greater than 1.5 hours. That will account for circumstances where the Driver isn't working and we aren't being billed, such as during equipment breakdowns.

I'm not much of a formulas guy so I hope this suffice your needs.

First I added a column to your sheet, to calculate how many amount of hours is taking for every single row, to do that I made use of the TIMEVALUE function:

=(TIMEVALUE(E2)-TIMEVALUE(D2))*24

时间示例

Now you just need to get all the driver's hours and tons and make the quotient total_tons / total_hours . For that they may be some other functions that would do the job, myself I have used QUERY :

=QUERY(Sheet1!A:M, "select C, sum(I), sum(M), sum(I) / sum(M) group by C", 1)

I think pretty straightforward query, group all the data by C (Driver's name) and then sum the column I (tons) and the column M (hours).

With the following result:

最后结果

The format may be a little off but you can change it as mush as you want. You can copy or play with the sheet


EDIT

After you change your requirements I made a change to my formula to calculate the hours worked:

=IF(
    AND(
        C3=C2, 
        A3=A2, 
        IFERROR(
               (TIMEVALUE(E3)-TIMEVALUE(D2))*24) <= 1.5, 
                TRUE
        ), 
    (TIMEVALUE(E3)-TIMEVALUE(D2))*24, 
    (TIMEVALUE(E2)-TIMEVALUE(D2))*24
)

Let me explain here, before there was a much simpler formula but now having multiple rows that we need to check makes the formula more lenghty.

First with the IF and AND statement we check if the next row has:

  • The same day ( A3=A2 )
  • The same Driver ( C3=C2 )
  • Less than an hour and a half of difference ( TIMEVALUE(E3)-TIMEVALUE(D2))*24) <= 1.5 )

And also because the last row throws an error trying to TIMEVALUE an empty column I had to add the IFERROR

After that the TRUE condition (same day, same driver, under 1.5h hours difference) will calculate from the current Time in ( D2 ) to the next Time in ( D3 ):

(TIMEVALUE(D3)-TIMEVALUE(D2))*24

And in the FALSE statement we do the same we were doing before:

(TIMEVALUE(E2)-TIMEVALUE(D2))*24

The QUERY function stays the same. And the results have decreased drastically:

编辑结果

If you have any doubts you can go ahead and see the sheet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM