Retrieving days per month that tanks are empty using filling and emptying dates

AllardZ

New Member
Joined
Dec 22, 2022
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
Hi everyone. First post here, so please let me know if anything is not according to the guidelines.

This is a snippet from a table in which data is collected from the brewery I work at (not all columns are depicted):

batch # tank numberbrew dateempty date
22.2711715-08-2230-08-22
22.2721715-08-2230-08-22
22.2731816-08-2208-09-22
22.2741816-08-2208-09-22
22.2751317-08-2202-09-22
22.2761317-08-2202-09-22
22.277418-08-2201-09-22
22.278119-08-2219-09-22
22.279522-08-2206-09-22
22.280622-08-2206-09-22
22.2811623-08-2209-09-22
22.2821623-08-2209-09-22
22.2831524-08-2207-09-22
22.2841524-08-2207-09-22
22.2851425-08-2212-09-22
22.2861425-08-2212-09-22
22.2871129-08-2213-09-22
22.2881129-08-2213-09-22
22.2891230-08-2216-09-22
22.2901230-08-2216-09-22
22.2911731-08-2214-09-22
22.2921731-08-2214-09-22
22.293701-09-2215-09-22
22.294805-09-2220-09-22
22.295405-09-2219-09-22
22.296906-09-2220-09-22
22.2971306-09-2221-09-22
22.2981306-09-2221-09-22
22.299207-09-2222-09-22
22.3001508-09-2223-09-22
22.3011508-09-2223-09-22
22.302609-09-2222-09-22
22.3031612-09-2226-09-22
22.3041612-09-2226-09-22
22.3051813-09-2229-09-22
22.3061813-09-2229-09-22
22.307314-09-2227-09-22
22.308514-09-2230-09-22
22.3091115-09-2203-10-22
22.3101115-09-2203-10-22
22.311719-09-2207-10-22
22.3121219-09-2204-10-22
22.3131220-09-2204-10-22
22.3141420-09-2205-10-22
22.3151421-09-2205-10-22
22.316821-09-2210-10-22
22.317122-09-2206-10-22
22.318422-09-2206-10-22
22.3191726-09-2212-10-22
22.3201726-09-2212-10-22
22.3211327-09-2213-10-22
22.3221327-09-2213-10-22
22.3231529-09-2214-10-22
22.3241529-09-2214-10-22
22.325230-09-2217-10-22
22.326630-09-2217-10-22
22.327303-10-2219-10-22
22.328904-10-2219-10-22
22.3291105-10-2221-10-22
22.3301206-10-2220-10-22
22.3311206-10-2220-10-22
22.332410-10-2224-10-22
22.333710-10-2227-10-22
22.3341411-10-2225-10-22
22.3351411-10-2225-10-22
22.3361612-10-2226-10-22
22.3371612-10-2226-10-22
22.3381713-10-2227-10-22
22.3391713-10-2227-10-22
22.340814-10-2228-10-22
22.341514-10-2228-10-22
22.342117-10-2231-10-22
22.3431317-10-2201-11-22
22.3441317-10-2201-11-22
22.345618-10-2231-10-22
22.3461519-10-2202-11-22
22.3471519-10-2202-11-22
22.3481820-10-2203-11-22
22.3491820-10-2203-11-22
22.350221-10-2207-11-22
22.351321-10-2207-11-22
22.3521124-10-2208-11-22
22.3531124-10-228-11-22
22.3541225-10-229-11-22
22.3551225-10-229-11-22
22.3561426-10-2215-11-22
22.3571426-10-2215-11-22
22.3581627-10-2214-11-22
22.3591627-10-2214-11-22
22.360928-10-2210-11-22
22.361428-10-2216-11-22
22.3621731-10-2218-11-22
22.3631731-10-2218-11-22
22.36471-11-2216-11-22
22.36581-11-2217-11-22
22.366132-11-2217-11-22
22.367132-11-2217-11-22
22.368153-11-227-12-22
22.369153-11-227-12-22
22.370187-11-2222-11-22
22.371187-11-2222-11-22
22.37218-11-2221-11-22
22.37328-11-2221-11-22
22.374119-11-2223-11-22
22.375119-11-2223-11-22
22.3761210-11-2225-11-22
22.3771210-11-2225-11-22
22.378311-11-2224-11-22
22.379511-11-2229-11-22
22.380614-11-2228-11-22
22.381914-11-2228-11-22
22.3821615-11-221-12-22
22.3831615-11-221-12-22


It has columns for batch number, tank number, brew date and tank emptying date. Now, I need to extract the number of days, by month, that a tank is unused, i.e. empty. For example, tank 5 was emptied on the 6th of september, but subsequently filled on the 14th, so it was empty for the 7 days in between. To make things even more complicated (at least to me): if a tank was emptied on a Friday, but filled on a Monday, the weekend shouldn't be considered as unused days.

I've been thinking of a way to subtract the filling date of a tank from the previous emptying date of said tank, but that does not give me dates. I'm thinking it might not be possible with just a pivot table, maybe a VBA code that loops through all the days, per tank, and registers the ones that don't fall in between filling and emptying dates? What would that look like?

Any ideas? I did find out it seems to resemble some questions related to employee absence days calculations, but I haven't been able to find a suitable solutions.

Thank you in advance,
Allard
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I have created a table for all the tank numbers and Inserted formulas to get the information

1672421553046.png


I have noticed that there are duplications of empty dates with the same tank number, is this relevant? If not, then they below might help.

In H3 the formula to bring back the last Brew Date is
1672421615570.png

In I3 the formula to bring back the last but one Empty Date is
1672421748038.png

To work out the the difference in days is in J3, excluding Weekends
1672421821860.png

There are other formulas that you can use, depending on the version of Excel.

Hope this helps
 
Upvote 0
I have created a table for all the tank numbers and Inserted formulas to get the information

View attachment 81792

I have noticed that there are duplications of empty dates with the same tank number, is this relevant? If not, then they below might help.

In H3 the formula to bring back the last Brew Date is
View attachment 81793
In I3 the formula to bring back the last but one Empty Date is
View attachment 81794
To work out the the difference in days is in J3, excluding Weekends
View attachment 81795
There are other formulas that you can use, depending on the version of Excel.

Hope this helps
Hi,

Thank you very much for your quick answer and effort. Much appreciated. I haven't used AGGREGATE at all yet, so figuring out what you've done here taught me some new tricks.

Could you please explain the reason for subtracting ROW($D$2)?

We use Excel 365, version 2211.

I haven't been able to make these formulas work for me completely yet, but it also isn't the exact format I'm looking for. The optimal format would be a (pivot) table that has months/years as columns, tank numbers as rows and 'days empty' as values. In other words, specified per month. Do you think this is possible?

Duplications of empty dates is because of multiple brews being fermented in the same tank, but this could be filtered by the column that specifies whether it's the first or second brew per tank.
 
Upvote 0
In the aggregate function, you need to indicate the number of Rows within the Array, not the row numbers on the excel sheet. So the first part will give you row numbers 3-107. What you need is the numbers 1-105, so in order to get that you subtract the Row D2.

As you are using 365, you can use other functions.

Try the below:
Brew Dates.xlsx
BCDEG
2batch #tank numberbrew dateempty dateDays
322.2711715/08/202230/08/2022-12
422.2721715/08/202230/08/2022 
522.2731816/08/202208/09/2022 
622.2741816/08/202208/09/2022 
722.2751317/08/202202/09/2022 
822.2761317/08/202202/09/2022 
922.277418/08/202201/09/2022 
1022.278119/08/202219/09/2022 
1122.279522/08/202206/09/2022 
1222.28622/08/202206/09/2022 
1322.2811623/08/202209/09/2022 
1422.2821623/08/202209/09/2022 
1522.2831524/08/202207/09/2022 
1622.2841524/08/202207/09/2022 
1722.2851425/08/202212/09/2022 
1822.2861425/08/202212/09/2022 
1922.2871129/08/202213/09/2022 
2022.2881129/08/202213/09/2022 
2122.2891230/08/202216/09/2022 
2222.291230/08/202216/09/2022 
2322.2911731/08/202214/09/20222
2422.2921731/08/202214/09/2022 
2522.293701/09/202215/09/2022 
2622.294805/09/202220/09/2022 
2722.295405/09/202219/09/20223
2822.296906/09/202220/09/2022 
2922.2971306/09/202221/09/20223
3022.2981306/09/202221/09/2022 
3122.299207/09/202222/09/2022 
3222.31508/09/202223/09/20222
3322.3011508/09/202223/09/2022 
3422.302609/09/202222/09/20224
3522.3031612/09/202226/09/20222
3622.3041612/09/202226/09/2022 
3722.3051813/09/202229/09/20224
3822.3061813/09/202229/09/2022 
3922.307314/09/202227/09/2022 
4022.308514/09/202230/09/20227
4122.3091115/09/202203/10/20223
4222.311115/09/202203/10/2022 
4322.311719/09/202207/10/20223
4422.3121219/09/202204/10/20222
4522.3131220/09/202204/10/2022-11
4622.3141420/09/202205/10/20227
4722.3151421/09/202205/10/2022-11
4822.316821/09/202210/10/20222
4922.317122/09/202206/10/20224
5022.318422/09/202206/10/20224
5122.3191726/09/202212/10/20229
5222.321726/09/202212/10/2022 
5322.3211327/09/202213/10/20225
5422.3221327/09/202213/10/2022 
5522.3231529/09/202214/10/20225
5622.3241529/09/202214/10/2022 
5722.325230/09/202217/10/20227
5822.326630/09/202217/10/20227
5922.327303/10/202219/10/20225
6022.328904/10/202219/10/202211
6122.3291105/10/202221/10/20223
6222.331206/10/202220/10/20223
6322.3311206/10/202220/10/2022 
6422.332410/10/202224/10/20223
6522.333710/10/202227/10/20222
6622.3341411/10/202225/10/20225
6722.3351411/10/202225/10/2022 
6822.3361612/10/202226/10/202213
6922.3371612/10/202226/10/2022 
7022.3381713/10/202227/10/20222
7122.3391713/10/202227/10/2022 
7222.34814/10/202228/10/20225
7322.341514/10/202228/10/202211
7422.342117/10/202231/10/20228
7522.3431317/10/202201/11/20223
7622.3441317/10/202201/11/2022 
7722.345618/10/202231/10/20222
7822.3461519/10/202202/11/20224
7922.3471519/10/202202/11/2022 
8022.3481820/10/202203/11/202216
8122.3491820/10/202203/11/2022 
8222.35221/10/202207/11/20225
8322.351321/10/202207/11/20223
8422.3521124/10/202208/11/20222
8522.3531124/10/202208/11/2022 
8622.3541225/10/202209/11/20224
8722.3551225/10/202209/11/2022 
8822.3561426/10/202215/11/20222
8922.3581627/10/202214/11/20222
9022.3591627/10/202214/11/2022 
9122.36928/10/202210/11/20228
9222.361428/10/202216/11/20225
9322.3621731/10/202218/11/20223
9422.364701/11/202216/11/20224
9522.365801/11/202217/11/20223
9622.3661302/11/202217/11/20222
9722.3681503/11/202207/12/20222
9822.371807/11/202222/11/20223
9922.372108/11/202221/11/20227
10022.373208/11/202221/11/20222
10122.3741109/11/202223/11/20222
10222.3761210/11/202225/11/20222
10322.378311/11/202224/11/20225
10422.379511/11/202229/11/202211
10522.38614/11/202228/11/202211
10622.381914/11/202228/11/20223
10722.3821615/11/202201/12/20222
Sheet1
Cell Formulas
RangeFormula
G3:G4G3=IF(OR(F3="",MAXIFS($E2:E$3,$C2:C$3,C3,$F2:F$3,1)<1),"",NETWORKDAYS.INTL(MAXIFS($E2:E$3,$C2:C$3,C3,$F2:F$3,1),[@[brew date]],1))
G5:G107G5=IF(OR(F5="",MAXIFS($E$3:E4,$C$3:C4,C5,$F$3:F4,1)<1),"",NETWORKDAYS.INTL(MAXIFS($E$3:E4,$C$3:C4,C5,$F$3:F4,1),[@[brew date]],1))
Named Ranges
NameRefers ToCells
brew_date=Sheet1!$D$3:$D$107G3
empty_date=Sheet1!$E$3:$E$107G3:G107
tank_number=Sheet1!$C$3:$C$107G3:G107


From this table you should be able to create a Pivot Table, as you wanted.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,956
Members
449,096
Latest member
Anshu121

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