Count of Value between Hours

TitansGO

New Member
Joined
Aug 3, 2016
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I hope someone can help me out with a pivot table problem that I've yet tofigure out.

I have a table setup that counts the number of instances that a trailerdelivers on an hourly basis. E.g., we have 7 deliveries at 08:00 AM. Most ofour deliveries are given an hour to complete the unloading process, but we havea select few that are given two hours. Below is an example of how therelevant data is inputted into the sheet.


Trailer
Version
Delivery
Freq

Delivery Days
Carrier
SCAC
Code

Commodity /
Supplier

Dock / Delivery Times
Unload/Reload
Delivery
Window
Start

Delivery
Window
End

ZZZZ
1
5
MTWRF
ZZZZ
ZZZZ
132: 0:00-1:00
Unload / Reload
0:00
1:00

<tbody>
</tbody>


The pivot table is essentially counting the number of trailers at the timedefined by delivery window start. I.e., DeliveryWindowStart as the row andcount of trailer as the values. The end result is like this...



Window
Deliveries
12 AM
1
1 AM
1
2 AM
1
3 AM
1
4 AM
1
5 AM
1
6 AM
1
7 AM
1
8 AM
9 AM
1
10 AM
1
11 AM
1
12 PM
1
1 PM
1
2 PM
1
3 PM
1
4 PM
5 PM
1
6 PM
1
7 PM
1
8 PM
1
9 PM
1
10 PM
1
11 PM
1
Grand Total
21

<tbody>
</tbody>





The exact problem is when the deliverywindow end isn’t an hour after the start. If they take 2 hours to work a trailer,then it wouldn’t actually depart until 2:00 AM using the example data inputabove. Below is how I would input it into the sheet.

Trailer
Version
Delivery
Freq

Delivery Days
Carrier
SCAC
Code

Commodity /
Supplier

Dock / Delivery Times
Unload/Reload
Delivery
Window
Start

Delivery
Window
End

ZZZZ
1
5
MTWRF
ZZZZ
ZZZZ
132: 0:00-2:00
Unload / Reload
0:00
2:00

<tbody>
</tbody>




That means there’s actually a 2ndtrailer being worked alongside the trailer that delivers at 1:00 AM. What Iwant my pivot table to show is below. How do I manipulate the pivot table tohelp me get there?

Window
Deliveries
12 AM
1
1 AM
2
2 AM
1
3 AM
1
4 AM
1
5 AM
1
6 AM
1
7 AM
1
8 AM
9 AM
1
10 AM
1
11 AM
1
12 PM
1
1 PM
1
2 PM
1
3 PM
1
4 PM
5 PM
1
6 PM
1
7 PM
1
8 PM
1
9 PM
1
10 PM
1
11 PM
1
Grand Total
21


<tbody>
</tbody>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,

Where are the 1's coming from? If a truck arrives at 01:00 and leaves at 02:00, should that show up as 1 or 2?

I can't imagine a Pivot solution, outside of adding columns for each time and a 1 or 0 if within that window.

Doesn't look like a pivot is needed though. I'd list all the times and use a COUNTIFS, something like this, depending on what you need.


Starting in P2:

00:00:00
00:01:00
02:00:00
03:00:00
04:00:00


<tbody>
</tbody>
Then Q2 =COUNTIFS(I:I,">"&P2,J:J,"<="&P2)

(this scenario would count the unit by departure time or in the process of loading for more than 1 hour units.)
 
Last edited:
Upvote 0
Hi,

Where are the 1's coming from? If a truck arrives at 01:00 and leaves at 02:00, should that show up as 1 or 2?

I can't imagine a Pivot solution, outside of adding columns for each time and a 1 or 0 if within that window.

Doesn't look like a pivot is needed though. I'd list all the times and use a COUNTIFS, something like this, depending on what you need.


Starting in P2:

00:00:00
00:01:00
02:00:00
03:00:00
04:00:00

<tbody>
</tbody>
Then Q2 =COUNTIFS(I:I,">"&P2,J:J,"<="&P2)

(this scenario would count the unit by departure time or in the process of loading for more than 1 hour units.)

TO answer your question for a truck from 0100 - 0200... that would be 1 truck at 0100. It would only count towards a 0200 if said truck had a loading time of 0100 - 0300. I.e., the count is based on the hour of the arrival time. Also, I'm not sure what it is your formula counts, but it doesn't seem to work for me.

I'd like to keep using the pivot table simply because of the ease of use for the end user. I created a dashboard built around that pivot table and would hate to scrap it if I know there's some way to incorporate what I'm looking for into said pivot.

Is there a way to perhaps work through this issue in Power Pivot? Kind of lost on how to proceed here. :confused:
 
Upvote 0
To go along the must be a pivot route, i'd add columns 00:00, 01:00 etc, starting in K1.

Then use: =IF(AND($I2<=K$1,OR($J2=K$1+(1/24),$J2=K$1+(2/24))),1,0)

You'd then need to add all those columns to the pivot as values, then drag values from columns to rows to flip it.
 
Last edited:
Upvote 0
Slight adjustment to deal with midnight and 2 hour unloads

=IF(AND(OR(K$1=(23/24),K$1=0),$I2=(23/24)),1,IF(AND($I2 < =K$1,OR($J2=K$1+(1/24),$J2=K$1+(2/24))),1,0))
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top