Count days between date range based on additional critiera

Fildes

New Member
Joined
Feb 8, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
My first post - I see some amazing formulas here.

I feel like I am so close to achieving an outcome. I would like to acknowledge StarLux for getting me so close -

This formauila is currrenlty in cells G8 to G12 - =IF(COUNTIFS($B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5)=0,0,SUMPRODUCT((($D$3:$D$40=F8))/COUNTIFS($D$3:$D$40,$D$3:$D$40&"",$B$3:$B$40,$B$3:$B$40&"",$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5)))

There are multiple entries for each plantation each day but I only want to count how many days in a set period the plantation name is mentioned regardless of the number of times it is mentioned each day, so from the image below "LAKE MUIR" is mentioned on 3 days (1st, 7th & 8th). Data will be added to this spreadsheet on a daily basis so ideally, I want the range to have a much bigger range but as soon as I extend the range so it covers other months I get an error. The results below are correct so the formula works but it cannot handle dates in column B not in the range in F5 & G5. I basically want all the references in the above formula to 40 to be 4000.

1581148382371.png


Thanks

Craig
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Welcome to Mr Excel :)

See if this works

=SUM(IFERROR(1/COUNTIFS($D$3:$D$40,$D$3:$D$40&"",$D$3:$D$30,$F8,$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5),0))

Rather than increasing the formula to 4000 rows, using a dynamic range would be a better option once the formula is tested and working with a smaller range.

For future reference, it is better to upload data samples in a format that we can copy and paste to excel so that formulas can be tested without having to retype your data first.
If you are able to install the add-in XL2BB - Excel Range to BBCode
 
Upvote 0
Thanks jasonb75.

This hasn't worked, unfortunately, but I have installed the XL2BB as you suggested and now pasted below. When you say to use a dynamic range are you saying assign the column a name. If I change the formula to $D:$D instead $D$2:$D$4000 it takes forever to calculate on this particular formula. I have never seen Excel stall to calculate before even on some long array formulas

Book122.xlsx
BCDEFGHI
1
2Date_1Date_2Plantation
315/11/19 0:0015/11/19 8:55 LAKE MUIR
415/11/19 0:0015/11/19 10:27 LAKE MUIRStart DateEnd Date
515/11/19 0:0015/11/19 15:45 LAKE MUIR01/11/1930/11/19
615/11/19 0:0015/11/19 16:26 LAKE MUIR
715/11/19 0:0015/11/19 16:35HICKS PlantationDay CountMr Excel
815/11/19 0:0015/11/19 18:24 LAKE MUIR LAKE MUIR#DIV/0!1
918/11/19 0:0018/11/19 9:31 LAKE MUIRPARTRIDGE 0
1018/11/19 0:0018/11/19 10:31 LAKE MUIRHICKS 5
1118/11/19 0:0018/11/19 11:57 LAKE MUIRSHEPHERD0
1218/11/19 0:0018/11/19 15:31 LAKE MUIRGLENN0
1318/11/19 0:0018/11/19 17:00 LAKE MUIR
1418/11/19 0:0018/11/19 18:23 LAKE MUIR
1518/11/19 0:0018/11/19 18:52HICKS
1619/11/19 0:0019/11/19 8:59 LAKE MUIR
1719/11/19 0:0019/11/19 10:21 LAKE MUIR
1819/11/19 0:0019/11/19 11:40 LAKE MUIR
1919/11/19 0:0019/11/19 15:02 LAKE MUIR
2019/11/19 0:0019/11/19 16:59 LAKE MUIR
2119/11/19 0:0019/11/19 17:13HICKS
2219/11/19 0:0019/11/19 18:10 LAKE MUIR
2320/11/19 0:0020/11/19 9:50 LAKE MUIR
2420/11/19 0:0020/11/19 11:36 LAKE MUIR
2520/11/19 0:0020/11/19 11:36 LAKE MUIR
2620/11/19 0:0020/11/19 14:32HICKS
2720/11/19 0:0020/11/19 16:02HICKS
2820/11/19 0:0020/11/19 17:49HICKS
2921/11/19 0:0021/11/19 7:38 FOUR WINDS
3021/11/19 0:0021/11/19 8:56 FOUR WINDS
3121/11/19 0:0021/11/19 10:44 FOUR WINDS
3221/11/19 0:0021/11/19 12:18 FOUR WINDS
3321/11/19 0:0021/11/19 14:10 FOUR WINDS
3421/11/19 0:0021/11/19 15:42HICKS
3521/11/19 0:0021/11/19 15:42HICKS
3621/11/19 0:0021/11/19 15:52 FOUR WINDS
3721/11/19 0:0021/11/19 17:18 FOUR WINDS
3822/11/19 0:0022/11/19 7:14 FOUR WINDS
3922/11/19 0:0022/11/19 9:10 FOUR WINDS
4022/11/19 0:0022/11/19 10:06 FOUR WINDS
4122/11/19 0:0022/11/19 12:07 FOUR WINDS
4222/11/19 0:0022/11/19 12:48HICKS
4322/11/19 0:0022/11/19 13:02 FOUR WINDS
4422/11/19 0:0022/11/19 14:53 FOUR WINDS
4522/11/19 0:0022/11/19 15:53HICKS
4622/11/19 0:0022/11/19 15:53HICKS
4722/11/19 0:0022/11/19 16:18 FOUR WINDS
4822/11/19 0:0022/11/19 17:50 FOUR WINDS
4925/11/19 0:0025/11/19 7:08 FOUR WINDS
5025/11/19 0:0025/11/19 8:37 FOUR WINDS
5125/11/19 0:0025/11/19 9:56 FOUR WINDS
5225/11/19 0:0025/11/19 11:19 FOUR WINDS
5325/11/19 0:0025/11/19 12:24 FOUR WINDS
5425/11/19 0:0025/11/19 13:54 FOUR WINDS
5525/11/19 0:0025/11/19 15:06 FOUR WINDS
5625/11/19 0:0025/11/19 16:56 FOUR WINDS
5725/11/19 0:0025/11/19 18:02 FOUR WINDS
5826/11/19 0:0026/11/19 7:19 FOUR WINDS
5926/11/19 0:0026/11/19 8:33 FOUR WINDS
6026/11/19 0:0026/11/19 10:02 FOUR WINDS
6126/11/19 0:0026/11/19 11:48 FOUR WINDS
6226/11/19 0:0026/11/19 12:54 FOUR WINDS
6326/11/19 0:0026/11/19 14:31HICKS
6426/11/19 0:0026/11/19 16:00 FOUR WINDS
6526/11/19 0:0026/11/19 17:02HICKS
6627/11/19 0:0027/11/19 7:13 FOUR WINDS
6727/11/19 0:0027/11/19 8:50 FOUR WINDS
6827/11/19 0:0027/11/19 10:31 FOUR WINDS
6927/11/19 0:0027/11/19 12:01 FOUR WINDS
7027/11/19 0:0027/11/19 13:47 FOUR WINDS
7127/11/19 0:0027/11/19 14:34HICKS
7227/11/19 0:0027/11/19 16:48 FOUR WINDS
7327/11/19 0:0027/11/19 17:17HICKS
7428/11/19 0:0028/11/19 7:52 FOUR WINDS
7528/11/19 0:0028/11/19 9:00 FOUR WINDS
7628/11/19 0:0028/11/19 10:27 FOUR WINDS
7728/11/19 0:0028/11/19 12:42 FOUR WINDS
7828/11/19 0:0028/11/19 14:22 FOUR WINDS
7928/11/19 0:0028/11/19 15:19HICKS
8028/11/19 0:0028/11/19 17:27 FOUR WINDS
8129/11/19 0:0029/11/19 7:05 FOUR WINDS
8229/11/19 0:0029/11/19 8:15 FOUR WINDS
8329/11/19 0:0029/11/19 9:58 FOUR WINDS
8429/11/19 0:0029/11/19 11:39HICKS
8529/11/19 0:0029/11/19 12:44 FOUR WINDS
8629/11/19 0:0029/11/19 14:10HICKS
8729/11/19 0:0029/11/19 15:48 FOUR WINDS
8829/11/19 0:0029/11/19 15:48 FOUR WINDS
8929/11/19 0:0029/11/19 17:04 FOUR WINDS
9002/12/19 0:0002/12/19 7:20 FOUR WINDS
9102/12/19 0:0002/12/19 8:27 FOUR WINDS
9202/12/19 0:0002/12/19 9:51 FOUR WINDS
9302/12/19 0:0002/12/19 11:26 FOUR WINDS
9402/12/19 0:0002/12/19 12:49 FOUR WINDS
9502/12/19 0:0002/12/19 14:37HICKS
9602/12/19 0:0002/12/19 14:52 FOUR WINDS
9702/12/19 0:0002/12/19 17:13 FOUR WINDS
9802/12/19 0:0002/12/19 17:21HICKS
9903/12/19 0:0003/12/19 7:07 FOUR WINDS
10003/12/19 0:0003/12/19 8:13 FOUR WINDS
10103/12/19 0:0003/12/19 11:44 FOUR WINDS
10203/12/19 0:0003/12/19 12:27HICKS
10303/12/19 0:0003/12/19 13:51 FOUR WINDS
10403/12/19 0:0003/12/19 15:27 FOUR WINDS
10503/12/19 0:0003/12/19 16:37 FOUR WINDS
10604/12/19 0:0004/12/19 7:00 FOUR WINDS
10704/12/19 0:0004/12/19 8:26 FOUR WINDS
10804/12/19 0:0004/12/19 9:45 FOUR WINDS
10904/12/19 0:0004/12/19 11:17 FOUR WINDS
11004/12/19 0:0004/12/19 12:18 FOUR WINDS
11104/12/19 0:0004/12/19 13:55 FOUR WINDS
11204/12/19 0:0004/12/19 15:08 FOUR WINDS
11304/12/19 0:0004/12/19 16:30HICKS
11404/12/19 0:0004/12/19 16:46 FOUR WINDS
11504/12/19 0:0004/12/19 17:49 FOUR WINDS
11605/12/19 0:0005/12/19 7:25 FOUR WINDS
11705/12/19 0:0005/12/19 7:58HICKS
11805/12/19 0:0005/12/19 8:58 FOUR WINDS
11905/12/19 0:0005/12/19 10:24 FOUR WINDS
12005/12/19 0:0005/12/19 11:04HICKS
12105/12/19 0:0005/12/19 12:08 FOUR WINDS
12205/12/19 0:0005/12/19 13:26 FOUR WINDS
12305/12/19 0:0005/12/19 15:16 FOUR WINDS
12405/12/19 0:0005/12/19 17:18 FOUR WINDS
12505/12/19 0:0005/12/19 17:18 FOUR WINDS
Sheet1
Cell Formulas
RangeFormula
I8I8=SUM(IFERROR(1/COUNTIFS($D$3:$D$40,$D$3:$D$40&"",$D$3:$D$40,$F8,$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5),0))
G8G8=IF(COUNTIFS($B$3:$B$4000,">="&$F$5,$B$3:$B$4000,"<="&$G$5)=0,0,SUMPRODUCT((($D$3:$D$4000=F8))/COUNTIFS($D$3:$D$4000,$D$3:$D$4000&"",$B$3:$B$4000,$B$3:$B$4000&"",$B$3:$B$4000,">="&$F$5,$B$3:$B$4000,"<="&$G$5)))
G9:G12G9=IF(COUNTIFS($B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5)=0,0,SUMPRODUCT((($D$3:$D$40=F9))/COUNTIFS($D$3:$D$40,$D$3:$D$40&"",$B$3:$B$40,$B$3:$B$40&"",$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5)))
B3:B125B3=TRUNC(P3)
 
Upvote 0
Hi, Craig.

Try this corrected version of the formula, because I didn't have data to test the first one on, I didn't notice that one of the ranges was missing (there was a typo, but I see that you corrected that).

=SUM(IFERROR(1/COUNTIFS($D$3:$D$40,$D$3:$D$40,$D$3:$D$40,$F8,$B$3:$B$40,$B$3:$B$40,$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5),0))

Also, I neglected to mention that the formula needs to be array confirmed with Ctrl Shift Enter, not just Enter.

As for dynamic ranges, no not full colums, trying to process over 1 million rows will always cause things to hang. You can do it by defined names, of within the formula. Instead of $D$3:$D$40 you would use $D$3:INDEX($D$D,MATCH("zzzz",$D$D)) using MATCH to find the last row of data.

To make it more efficient, you could enter =MATCH("zzzz",$D$D) into F1, then use $D$3:INDEX($D:$D,$F$1) in the main formula. That way the MATCH function only has to calculate once for all of the formulas rather than 7 times for each formula.

Book1
BCDEFGH
150
2Date_1Date_2Plantation
315/11/201915/11/2019 08:55:00LAKE MUIR
415/11/201915/11/2019 10:27:00LAKE MUIRStart DateEnd Date
515/11/201915/11/2019 15:45:00LAKE MUIR01/11/201930/11/2019
615/11/201915/11/2019 16:26:00LAKE MUIR
715/11/201915/11/2019 16:35:00HICKSPlantationMr ExcelDynamic
815/11/201915/11/2019 18:24:00LAKE MUIRLAKE MUIR44
918/11/201918/11/2019 09:31:00LAKE MUIRPARTRIDGE00
1018/11/201918/11/2019 10:31:00LAKE MUIRHICKS56
1118/11/201918/11/2019 11:57:00LAKE MUIRSHEPHERD00
1218/11/201918/11/2019 15:31:00LAKE MUIRGLENN00
1318/11/201918/11/2019 17:00:00LAKE MUIRFOUR WINDS23
1418/11/201918/11/2019 18:23:00LAKE MUIR
1518/11/201918/11/2019 18:52:00HICKS
1619/11/201919/11/2019 08:59:00LAKE MUIR
1719/11/201919/11/2019 10:21:00LAKE MUIR
1819/11/201919/11/2019 11:40:00LAKE MUIR
1919/11/201919/11/2019 15:02:00LAKE MUIR
2019/11/201919/11/2019 16:59:00LAKE MUIR
2119/11/201919/11/2019 17:13:00HICKS
2219/11/201919/11/2019 18:10:00LAKE MUIR
2320/11/201920/11/2019 09:50:00LAKE MUIR
2420/11/201920/11/2019 11:36:00LAKE MUIR
2520/11/201920/11/2019 11:36:00LAKE MUIR
2620/11/201920/11/2019 14:32:00HICKS
2720/11/201920/11/2019 16:02:00HICKS
2820/11/201920/11/2019 17:49:00HICKS
2921/11/201921/11/2019 07:38:00FOUR WINDS
3021/11/201921/11/2019 08:56:00FOUR WINDS
3121/11/201921/11/2019 10:44:00FOUR WINDS
3221/11/201921/11/2019 12:18:00FOUR WINDS
3321/11/201921/11/2019 14:10:00FOUR WINDS
3421/11/201921/11/2019 15:42:00HICKS
3521/11/201921/11/2019 15:42:00HICKS
3621/11/201921/11/2019 15:52:00FOUR WINDS
3721/11/201921/11/2019 17:18:00FOUR WINDS
3822/11/201922/11/2019 07:14:00FOUR WINDS
3922/11/201922/11/2019 09:10:00FOUR WINDS
4022/11/201922/11/2019 10:06:00FOUR WINDS
4122/11/201922/11/2019 12:07:00FOUR WINDS
4222/11/201922/11/2019 12:48:00HICKS
4322/11/201922/11/2019 13:02:00FOUR WINDS
4422/11/201922/11/2019 14:53:00FOUR WINDS
4522/11/201922/11/2019 15:53:00HICKS
4622/11/201922/11/2019 15:53:00HICKS
4722/11/201922/11/2019 16:18:00FOUR WINDS
4822/11/201922/11/2019 17:50:00FOUR WINDS
4925/11/201925/11/2019 07:08:00FOUR WINDS
5025/11/201925/11/2019 08:37:00FOUR WINDS
Sheet3
Cell Formulas
RangeFormula
F1F1=MATCH("zzzz",$D:$D)
G8:G13G8{=SUM(IFERROR(1/COUNTIFS($D$3:$D$40,$D$3:$D$40,$D$3:$D$40,$F8,$B$3:$B$40,$B$3:$B$40,$B$3:$B$40,">="&$F$5,$B$3:$B$40,"<="&$G$5),0))}
H8:H13H8{=SUM(IFERROR(1/COUNTIFS($D$3:INDEX($D:$D,$F$1),$D$3:INDEX($D:$D,$F$1),$D$3:INDEX($D:$D,$F$1),$F8,$B$3:INDEX($B:$B,$F$1),$B$3:INDEX($B:$B,$F$1),$B$3:INDEX($B:$B,$F$1),">="&$F$5,$B$3:INDEX($B:$B,$F$1),"<="&$G$5),0))}
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Hi Jason, thank you so much for the quick reply; this works nicely. I see I still have a lot to learn.

Well done

Craig
 
Upvote 0
Glad to hear that it worked, thanks for the feedback :)

I still have a lot to learn.
Everyone here does, although there are probably a few that think they know everything :unsure:
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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