Count Only Visible Days

honkin

Active Member
Joined
Mar 20, 2012
Messages
385
Office Version
  1. 2016
Platform
  1. MacOS
Can the DAYS function be adapted to only count visible cells?

What I am trying to do is to divide the number of days between 2 dates into the number of selections I have. This tell me how many selections per day I have. Here is the formula I have:

Code:
=F5549/DAYS(A5524,A3)

This works alright when the sheet is unfiltered, but when I autofilter selections for certain criteria, it still counts the days from the first date in A3 to the last date in A5524. I would like it to only count the actual number of days showing from the first visible cell to the last visible cell. On some days there may be no selections, so I I don't want it to count simply from start date to finish date. I need it to differentiate when NO days are showing.

19/01/2017Thursday14:35
20/01/2017Friday19:15
20/01/2017Friday20:00
24/01/2017Tuesday14:40
25/01/2017Wednesday13:35
25/01/2017Wednesday15:50
31/01/2017Tuesday15:20
01/02/2017Wednesday18:30
02/02/2017Thursday21:00
03/02/2017Friday16:10
04/02/2017Saturday14:00
09/02/2017Thursday14:05
10/02/2017Friday18:15
10/02/2017Friday18:45
11/02/2017Saturday16:20


As you can see with this, there are only 12 actual days with entries, but if you counted from 19 Jan 2017 to 11 Feb 2017, you would get 24 days. I hope that clarifies it a little

Is there a way to adjust this to achieve what I am after?

cheers
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Excel Formula:
=AGGREGATE(2,5,a3:a2254)
will only count visible rows so even when nothing is unvisible it still works
See what AGGREGATE can do
Thanks very much for your reply, Arthur, but it doesn't appear to work with dates very well. The DAYS function shows there are 1519 days from 1 Jan 2017 to 28 Feb 2021. This answer is correct, as I checked it online. Using the Aggregate function, it gave the answer of 63,388, which is the actual number or rows of data. So it seems to be just tallying all visible rows, which is not what I need. Thanks again for your reply
 
Upvote 0
Try this formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(a3:a70000,ROW(a3:a70000)-ROW(a3),0,1)))

Count ONLY visible cells.
 
Upvote 0
In addition to what already posted by Tom.Jones, above...
It would be simple with a helper column; for example set in D3 this formula:
=SUBTOTAL(103,A3)*(COUNTIF($A2:$A$3,A3)=0)
Then copy D3 down to D6000

You can count the unique days in the visible rows using
=SUM(D3:D6000)

Bye
 
Upvote 0
Try this formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(a3:a70000,ROW(a3:a70000)-ROW(a3),0,1)))

Count ONLY visible cells.
Cheers Tom. It's definitely heading in the right area. I was trying to work out how to use SUBTOTAL. What this does is count ALL the visible cells within the range, regardless of the dates. It is basically doing exactly the same as =SUBTOTAL(103,A3:A70000)

LTP Jumps.xlsx
ABC
2103/01/2017Tuesday14:30
2113/01/2017Tuesday14:50
2123/01/2017Tuesday14:50
2133/01/2017Tuesday14:50
2144/01/2017Wednesday12:55
2154/01/2017Wednesday12:55
2164/01/2017Wednesday12:55
2174/01/2017Wednesday12:55
2184/01/2017Wednesday12:55
Sheet1


So as an example, here are 9 rows, yet there are only 2 actual days displayed. The answer is 9, but it needs to be 2. It can't count duplicate days, but blowed if I can find a way to exclude them
 
Upvote 0
In addition to what already posted by Tom.Jones, above...
It would be simple with a helper column; for example set in D3 this formula:
=SUBTOTAL(103,A3)*(COUNTIF($A2:$A$3,A3)=0)
Then copy D3 down to D6000

You can count the unique days in the visible rows using
=SUM(D3:D6000)

Bye
Thanks so much for your reply, Anthony. OK, so the idea is that gives a 1 every time the date changes, yeah? Then we tally the visible 1s to check for the number of days. Again, it seems to fall over when the data is autofiltered.

LTP Jumps.xlsx
ABC
6265118/02/2021Thursday0
6265218/02/2021Thursday0
6265318/02/2021Thursday0
6265418/02/2021Thursday0
6265518/02/2021Thursday0
6265618/02/2021Thursday0
6269619/02/2021Friday0
6269719/02/2021Friday0
6269819/02/2021Friday0
6269919/02/2021Friday0
6270019/02/2021Friday0
6306523/02/2021Tuesday0
6306623/02/2021Tuesday0
6306723/02/2021Tuesday0
6306823/02/2021Tuesday0
6310424/02/2021Wednesday0
6310524/02/2021Wednesday0
6310624/02/2021Wednesday0
6310724/02/2021Wednesday0
6336428/02/2021Sunday0
6336528/02/2021Sunday0
6336628/02/2021Sunday0
Sheet1
Cell Formulas
RangeFormula
C63364:C63366,C63104:C63107,C63065:C63068,C62696:C62700,C62651:C62656C62651=SUBTOTAL(103,A62651)*(COUNTIF($A$3:$A62650,A62651)=0)


Here you can see it is 18, 19, 23, 24 & 28 Jan, yet all the entries are 0s. It works fine when the sheet is left unfiltered, but the idea of this is to be able to filter for certain criteria and see how many selections there are per day. If unique days are not displayed, that calculation cannot take place.

Any thoughts on why it doesn't recalculate based on only visible data?

cheers
 
Upvote 0
Thanks very much for your reply, Arthur, but it doesn't appear to work with dates very well. The DAYS function shows there are 1519 days from 1 Jan 2017 to 28 Feb 2021. This answer is correct, as I checked it online. Using the Aggregate function, it gave the answer of 63,388, which is the actual number or rows of data. So it seems to be just tallying all visible rows, which is not what I need. Thanks again for your reply
Yep I used the COUNT switch instead of the COUNTA one
Excel Formula:
 =AGGREGATE(3,5,a3:a2254)
 
Upvote 0
Do you mean your data spans from A3 to A63366?
I don't know if Subtotal(103 exists on Excel for Mac; try Subtotal(3:
Code:
=SUBTOTAL(3,A3)*(COUNTIF($A2:$A$3,A3)=0)
You should see a 1 on all the visible cells, if the date is not duplicated.

If it fails then I think you should share your worksheet with your real data

Bye

PS: don't miss arturbr message, above
And double check that your calculation mode is set to Automatic and not Manual
 
Upvote 0
This formula is not correct. See post #25

See if this example helps

Before filter
Pasta1
ABCDEF
1Unique Days
2DateWeekdayTimeCriteria7
319/01/2017Thursday14:35:00Yes
419/01/2017Thursday15:00:01No
519/01/2017Thursday15:01:01No
619/01/2017Thursday15:02:01No
719/01/2017Thursday15:03:01No
819/01/2017Thursday15:04:01No
919/01/2017Thursday15:05:01No
1020/01/2017Friday19:15:00Yes
1120/01/2017Friday20:00:00Yes
1221/01/2017Saturday20:01:00No
1321/01/2017Saturday20:02:00No
1422/01/2017Sunday15:01:01No
1522/01/2017Sunday15:02:01No
1623/01/2017Monday15:03:01No
1724/01/2017Tuesday14:40:00Yes
1824/01/2017Tuesday15:02:01No
1924/01/2017Tuesday15:03:01No
2025/01/2017Wednesday13:35:00Yes
2125/01/2017Wednesday14:00:00No
2225/01/2017Wednesday15:50:00Yes
23
Plan1
Cell Formulas
RangeFormula
F2F2=SUM(IFERROR(IF(FREQUENCY(A3:A6000,A3:A6000),IF(SUBTOTAL(3,OFFSET(A3:A6000,ROW(A3:A6000)-ROW(A3),0,1)),1)),0))
Press CTRL+SHIFT+ENTER to enter array formulas.


After filter (Criteria =Yes)
Pasta1
ABCDEF
1Unique Days
2DateWeekdayTimeCriteria4
319/01/2017Thursday14:35:00Yes
1020/01/2017Friday19:15:00Yes
1120/01/2017Friday20:00:00Yes
1724/01/2017Tuesday14:40:00Yes
2025/01/2017Wednesday13:35:00Yes
2225/01/2017Wednesday15:50:00Yes
23
Plan1
Cell Formulas
RangeFormula
F2F2=SUM(IFERROR(IF(FREQUENCY(A3:A6000,A3:A6000),IF(SUBTOTAL(3,OFFSET(A3:A6000,ROW(A3:A6000)-ROW(A3),0,1)),1)),0))
Press CTRL+SHIFT+ENTER to enter array formulas.


Array formula in F2 (must be confirmed with Ctrl+Shift+Enter)

M.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,987
Members
452,373
Latest member
TimReeks

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