Filter Spread sheet by date range and calculate difference between dates

SirSquiddly

New Member
Joined
Jun 26, 2018
Messages
40
Hi

I have a large spread sheet that needs to be analysed at the end of each month. I need some help trying to make this much more efficient.

Currently on hire dates are in a column (R) and off hire dates in the next (S).

R S
20/05/201906/06/2019
20/05/201906/06/2019
20/05/201906/06/2019
22/05/201908/06/2019
02/06/2019
24/05/2019
28/07/2019
28/07/201914/07/2019
28/07/2019
26/06/20195/08/2019

<colgroup><col><col></colgroup><tbody>
</tbody>

So I have to do a monthly report and need to filter out everything from other months and have a total day count as well. Lets use July for example. There are some hire tools that leave in June gone and return in august (bottom example above) or are not yet returned by months end (blank return column) but both would require 31 days for July. Also, there are some tools start date in June and return in July but I would only need to calculate the days for July.

Can anyone suggest an easier way to do this than manually sorting through the dates and adding 01/07/19 to some of the start dates and 31/07/2019 to the off hire dates. There are hundreds of rows each month.

Any help would be hugely appreciated. Thanks
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Two comments first:
- Please use a common date format in your questions as many Shermans use this site. I've changed to dd-mmm-yy format.
- The row "28/07/2019 14/07/2019" flummoxed me as it looks like they left before they started?

Is this the result you might expect? The first two columns are your dates, R2 and S2 and my MAX and MIN checks. The "Days in July" is my calculation. The top row 01-Jul-19 is where you type the first day of the month you're interested in. The 31-Jul-19 is just an =EOMONTH(G1,0) statement to get the last day of that month.

RSR2S2Days in July01-Jul-1931-Jul-19
20-May-1906-Jun-1901-Jul-1906-Jun-190
20-May-1906-Jun-1901-Jul-19
06-Jun-190
20-May-1906-Jun-1901-Jul-1906-Jun-190
22-May-1908-Jun-1901-Jul-1908-Jun-190
02-Jun-19 01-Jul-1931-Jul-1931
24-May-19 01-Jul-1931-Jul-1931
28-Jul-19 28-Jul-1931-Jul-194
28-Jul-1914-Jul-1928-Jul-1914-Jul-190
28-Jul-19 28-Jul-1931-Jul-194
26-Jun-1905-Aug-1901-Jul-1931-Jul-1931

<colgroup><col style="mso-width-source:userset;mso-width-alt:3165;width:68pt" width="91"> <col style="mso-width-source:userset;mso-width-alt:3304;width:71pt" width="95"> <col style="mso-width-source:userset;mso-width-alt:721;width:16pt" width="21"> <col style="mso-width-source:userset;mso-width-alt:3002;width:65pt" width="86"> <col style="mso-width-source:userset;mso-width-alt:2978;width:64pt" width="85"> <col style="mso-width-source:userset;mso-width-alt:3304;width:71pt" width="95"> <col style="mso-width-source:userset;mso-width-alt:2513;width:54pt" width="72"> <col style="mso-width-source:userset;mso-width-alt:2304;width:50pt" width="66"> </colgroup><tbody>
</tbody>


As formulae these appear as:
RSR2S2="Days in "&TEXT(G1,"mmmm")43647=EOMONTH(G1,0)
4360543622=MAX(A2,$G$1)=MIN(B2,$H$1)=IF(E2-D2<0,0,E2-D2+1)
4360543622=MAX(A3,$G$1)=MIN(B3,$H$1)=IF(E3-D3<0,0,E3-D3+1)
4360543622=MAX(A4,$G$1)=MIN(B4,$H$1)
=IF(E4-D4<0,0,E4-D4+1)
4360743624=MAX(A5,$G$1)=MIN(B5,$H$1)=IF(E5-D5<0,0,E5-D5+1)
43618 =MAX(A6,$G$1)=MIN(B6,$H$1)=IF(E6-D6<0,0,E6-D6+1)
43609 =MAX(A7,$G$1)=MIN(B7,$H$1)=IF(E7-D7<0,0,E7-D7+1)
43674 =MAX(A8,$G$1)=MIN(B8,$H$1)=IF(E8-D8<0,0,E8-D8+1)
4367443660=MAX(A9,$G$1)=MIN(B9,$H$1)=IF(E9-D9<0,0,E9-D9+1)
43674 =MAX(A10,$G$1)=MIN(B10,$H$1)=IF(E10-D10<0,0,E10-D10+1)
4364243682=MAX(A11,$G$1)=MIN(B11,$H$1)=IF(E11-D11<0,0,E11-D11+1)

<colgroup><col span="2"><col><col><col><col><col><col></colgroup><tbody>
</tbody>

Is that what you needed?
 
Upvote 0
Beautiful! Thank you very much! This will save me a lot of time and errors.

If you could advise or point me in the direction of my next step that would be unbelievable. I then calculate total cost (column T) by simply number of days * price per day. But my monthly report requires to work out the total cost per category of tool. So the description (column L) looks like:

SUB BIT
SUB BIT
SUB LIFT
SUB CROSSOVER
SUB FLOAT
SUB FLOAT NM
SUB FLOAT NM
(x200 +)

So is there a way to work out the total costs for each description (all July "SUB CROSSOVER" combined , all "SUB BITS" combined etc). There are about 40 unique descriptions. This could be in separate a sheet or wherever.

Again any guidance greatly appreciated.

Thanks
 
Upvote 0
SirSquiddly,

So I've trimmed the example data for brevity (and to remove the entry where they returned it before they hired it).

I've combined the 3 worker columns into 1, "Days in July". which now has this copied down from row 2 to whichever row has the last data:
=IF(R2&S2="","",IF(MIN(S2,$Z$2)-MAX(R2,$Z$1)<0,0,MIN(S2,$Z$2)-MAX(R2,$Z$1)+1))

To get that hire charge for July I take the daily hire charge for that tool and multiply it by the number of days hired:
=IF(L2="","",INDEX(PricePerDay,MATCH(L2,Tool,0))*U2)

Copy those two formulae columns down as far as the last hire data you'll ever have.

Let me show you this on Sheet3 before I explain the Tool Table I've put onto Sheet4

LRSTUVZ
1Tool HiredRSJuly chargeDays in July01-Jul-19
2SUB CROSSOVER22-May-1908-Jun-19 £ -031-Jul-19
3SUB FLOAT02-Jun-19 £ 255.7531
4SUB FLOAT NM24-May-19 £ 341.0031
5SUB FLOAT NM28-Jul-19 £ 44.004
6SUB CROSSOVER21-Jul-1927-Jul-19 £ 84.007
7SUB CROSSOVER26-Jun-1905-Aug-19 £ 372.0031

<tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
T1=TEXT(Z1,"mmmm")&" charge"
U1="Days in "&TEXT(Z1,"mmmm")
T2=IF(L2="","",INDEX(PricePerDay,MATCH(L2,Tool,0))*U2)
U2=IF(R2&S2="","",IF(MIN(S2,$Z$2)-MAX(R2,$Z$1)<0,0,MIN(S2,$Z$2)-MAX(R2,$Z$1)+1))
Z2=EOMONTH(Z1,0)

<tbody>
</tbody>

<tbody>
</tbody>

Workbook Defined Names
NameRefers To
PricePerDay=Sheet4!$B$2:$B$6
Tool=Sheet4!$A$2:$A$6

<tbody>
</tbody>

<tbody>
</tbody>


So Sheet4 is the Tool reference which is created by entering the headings (no hyphens or spaces, just underscores as separators) and then your Tool description and PricePerDay.

Then highlight all the cells and Insert, Table. Then with those cells still highlighted select Formulas, Create from Selection and use the Top row as the name. To add a new Tool go to the last cell and press Tab.
For MonthTotal enter
=SUMIFS(Sheet3!$T$2:$T$999,Sheet3!$L$2:$L$999,[@Tool])
where $999 is the last row you'll ever have hire data on Sheet3 and the Excel Table will automatically fill the formula down that column and add it if you add a new Tool row.

When you're done you can use Table Design and select Total Row to set a grand total for the month.

ABC
1ToolPricePerDayMonthTotal
2SUB BIT £ 5.50 £ -
3SUB LIFT £ 25.00 £ -
4SUB CROSSOVER £ 12.00 £ 456.00
5SUB FLOAT £ 8.25 £ 255.75
6SUB FLOAT NM £ 11.00 £ 385.00
7Total £ 1,096.75

<tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
C2=SUMIFS(Sheet3!$T$2:$T$999,Sheet3!$L$2:$L$999,[@Tool])
C7=SUBTOTAL(109,[MonthTotal])

<tbody>
</tbody>

<tbody>
</tbody>

Workbook Defined Names
NameRefers To
MonthTotal=Sheet4!$C$2:$C$6
Tool=Sheet4!$A$2:$A$6

<tbody>
</tbody>

<tbody>
</tbody>


On Sheet3 you enter the Tool Hired rows, start hire date and end hire dates into columns L, R and S.
In cell Z1 enter the first of the month you want calculated.
Columns T and U will show the charge and active days of hire for the selected month.
Sheet4 must have unique Tool descriptions but will then show you thetotal by Tool for the selected month.
 
Upvote 0
Agh oops!!! I should have been more clear....

Because there are different sizes within each category, there are different price ranges per day... so total days x 1 day price will be inaccurate. What I think we need to do is somehow get the tool category total from the sum of each (days * day price). But I am not sure how to go about this.


LT
1SUB LIFT £50
2SUB BIT£100
3SUB LIFT £ 25.00
4SUB CROSSOVER £ 12.00
5SUB BIT £ 200
6SUB FLOAT NM £ 100

<tbody style="border-collapse: collapse; border-spacing: 0px 0px; font-size: 13px; margin-bottom: 0px;">
</tbody>
So from the above table, I need:

1. SUB BIT £300
2. SUB LIFT £75
3. SUB FLOAT £100
ETC.


Is this possible?
 
Upvote 0
Yes, that's the column on the Tool table MonthTotal.

So if I change the test data to match your latest entries:

LRSTUVZ
1Tool HiredRSJuly chargeDays in July01-Jul-19
2SUB LIFT 21-Jul-1922-Jul-19 £ 50.00 231-Jul-19
3SUB BIT22-Jul-1922-Jul-19 £ 100.00 1
4SUB LIFT 01-Jul-1901-Jul-19 £ 25.00 1
5SUB CROSSOVER 29-Jul-1929-Jul-19 £ 12.00 1
6SUB BIT29-Jul-1930-Jul-19 £ 200.00 2
7SUB FLOAT NM21-Jul-1930-Jul-19 £ 100.00 10

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet3

Worksheet Formulas
CellFormula
T1=TEXT(Z1,"mmmm")&" charge"
U1="Days in "&TEXT(Z1,"mmmm")
T2=IF(L2="","",INDEX(PricePerDay,MATCH(L2,Tool,0))*U2)
U2=IF(R2&S2="","",IF(MIN(S2,$Z$2)-MAX(R2,$Z$1)<0,0,MIN(S2,$Z$2)-MAX(R2,$Z$1)+1))
Z2
=EOMONTH(Z1,0)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Workbook Defined Names
NameRefers To
PricePerDay=Sheet4!$B$2:$B$6
Tool=Sheet4!$A$2:$A$6

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



...then the Tool table shows the totals for each Tool:

ABC
1ToolPricePerDayMonthTotal
2SUB BIT £ 100.00 £ 300.00
3SUB LIFT £ 25.00 £ 75.00
4SUB CROSSOVER £ 12.00 £ 12.00
5SUB FLOAT £ 8.25 £ -
6SUB FLOAT NM £ 10.00 £ 100.00
7Total £ 487.00

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet4

Worksheet Formulas
CellFormula
C2=SUMIFS(Sheet3!$T$2:$T$999,Sheet3!$L$2:$L$999,[@Tool])
C7
=SUBTOTAL(109,[MonthTotal])

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Workbook Defined Names
NameRefers To
MonthTotal=Sheet4!$C$2:$C$6
Tool=Sheet4!$A$2:$A$6

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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