Sumproduct to countif

Akashwani

Well-known Member
Joined
Mar 14, 2009
Messages
2,911
Hi,

I want to count how many years (From date To date) include a particular year and return all relevant data.


Excel Workbook
ABCDE
1NameTransportColourFromTo
2BillBusRed02/02/200020/03/2004
3TomCarGreen02/02/200320/03/2004
4JoPlaneBlue02/02/200420/03/2006
5TimBoatYellow02/02/199920/03/2001
6SueTrainRed02/02/200220/03/2002
7DanBikeYellow02/02/200020/03/2001
8BobCarBlue02/02/200820/03/2009
9MoPlaneGreen02/02/200020/03/2002
10FloBusRed02/02/200220/03/2004
11JoePlaneGreen02/02/199920/03/2000
12JimBoatBlue02/02/200120/03/2002
13PatTrainRed02/02/200220/03/2002
Sheet1



Excel Workbook
ABCDEFG
1YearCount*****
22000644111
3*******
4NameTransportColourFromTo**
5BillBusRed02/02/200020/03/2004**
6TimBoatYellow02/02/199920/03/2001**
7DanBikeYellow02/02/200020/03/2001**
8MoPlaneGreen02/02/200020/03/2002**
9JoePlaneGreen02/02/199920/03/2000**
10#NUM!#NUM!#NUM!#NUM!#NUM!**
Sheet2




I know that I am doing something wrong with the Sumproduct formulas, but for the life of me I just cannot see it. The above Sumproduct needs to return 5, not 6 or 4 or 1 :rofl:

Can someone ease my mind?

Thanks

Ak
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,

I want to count how many years (From date To date) include a particular year and return all relevant data.


Excel Workbook
ABCDE
1NameTransportColourFromTo
2BillBusRed02/02/200020/03/2004
3TomCarGreen02/02/200320/03/2004
4JoPlaneBlue02/02/200420/03/2006
5TimBoatYellow02/02/199920/03/2001
6SueTrainRed02/02/200220/03/2002
7DanBikeYellow02/02/200020/03/2001
8BobCarBlue02/02/200820/03/2009
9MoPlaneGreen02/02/200020/03/2002
10FloBusRed02/02/200220/03/2004
11JoePlaneGreen02/02/199920/03/2000
12JimBoatBlue02/02/200120/03/2002
13PatTrainRed02/02/200220/03/2002
Sheet1



Excel Workbook
ABCDEFG
1YearCount*****
22000644111
3*******
4NameTransportColourFromTo**
5BillBusRed02/02/200020/03/2004**
6TimBoatYellow02/02/199920/03/2001**
7DanBikeYellow02/02/200020/03/2001**
8MoPlaneGreen02/02/200020/03/2002**
9JoePlaneGreen02/02/199920/03/2000**
10#NUM!#NUM!#NUM!#NUM!#NUM!**
Sheet2




I know that I am doing something wrong with the Sumproduct formulas, but for the life of me I just cannot see it. The above Sumproduct needs to return 5, not 6 or 4 or 1 :rofl:

Can someone ease my mind?

Thanks

Ak
One way...

=SUMPRODUCT(SIGN((YEAR(Sheet1!$D$2:$D$13)<=A2)+(YEAR(Sheet1!$E$2:$E$13)<=A2)))
 
Upvote 0
Hi,

Maybe

Formula in B2
=SUMPRODUCT(--(YEAR(Sheet1!D2:D13)<=A2),--(YEAR(Sheet1!E2:E13)>=A2))

HTH

M
 
Upvote 0
Akashwani,

Or try this formula (array formula - use Ctrl+Shift+Enter and not only Enter) in B2 of Sheet2:

=SUM(IF(YEAR(Sheet1!$D$2:$D$13)<=$A$2,IF(YEAR(Sheet1!$E$2:$E$13)>=$A$2,1,0),0))

Markmzz
 
Upvote 0
I think you guys are all missing the point.

The OP wants to count ROWS if the year in EITHER column is <= year 2000.

Book1
DEF
22/2/20003/20/20041
32/2/20033/20/2004_
42/2/20043/20/2006_
52/2/19993/20/20012
62/2/20023/20/2002_
72/2/20003/20/20013
82/2/20083/20/2009_
92/2/20003/20/20024
102/2/20023/20/2004_
112/2/19993/20/20005
122/2/20013/20/2002_
132/2/20023/20/2002_
Sheet1
 
Upvote 0
Hi all,

Thanks for your replies.
I've been playing around with this for some time now, this is what I'm getting...

Excel Workbook
ABCDE
1NameTransportColourFromTo
2BillBusRed02/02/200020/03/2004
3TomCarGreen02/02/199820/03/2004
4JoPlaneBlue02/02/200420/03/2006
5TimBoatYellow02/02/199920/03/2001
6SueTrainRed02/02/200220/03/2002
7DanBikeYellow02/02/200020/03/2001
8BobCarBlue02/02/200820/03/2009
9MoPlaneGreen02/02/200020/03/2002
10FloBusRed02/02/200220/03/2004
11JoePlaneGreen02/02/199920/03/2000
12JimBoatBlue02/02/200120/03/2002
13PatTrainRed02/02/200220/03/2002
Sheet1





Excel Workbook
ABCDE
1YearBiffMarceloKrisMarkmzz
220006666
3*****
4NameTransportColourFromTo
5BillBusRed02/02/200020/03/2004
6TomCarGreen02/02/199820/03/2004
7TimBoatYellow02/02/199920/03/2001
8DanBikeYellow02/02/200020/03/2001
9MoPlaneGreen02/02/200020/03/2002
10JoePlaneGreen02/02/199920/03/2000
11*****
12*****
Sheet2


OR....


Excel Workbook
ABCDE
1NameTransportColourFromTo
2BillBusRed02/02/200020/03/2004
3TomCarGreen02/02/199820/03/2004
4JoPlaneBlue02/02/200420/03/2006
5TimBoatYellow02/02/199920/03/2001
6SueTrainRed02/02/200220/03/2002
7DanBikeYellow02/02/200020/03/2001
8BobCarBlue02/02/200820/03/2009
9MoPlaneGreen02/02/200020/03/2002
10FloBusRed02/02/200220/03/2004
11JoePlaneGreen02/02/199920/03/2000
12JimBoatBlue02/02/200120/03/2002
13PatTrainRed02/02/200220/03/2002
Sheet1



Excel Workbook
ABCDE
1YearBiffMarceloKrisMarkmzz
2200411444
3*****
4NameTransportColourFromTo
5BillBusRed02/02/200020/03/2004
6TomCarGreen02/02/199820/03/2004
7JoPlaneBlue02/02/200420/03/2006
8TimBoatYellow02/02/199920/03/2001
Sheet2


As you can see in the first example everything is fine.
In the second example the formula from Biff counts every record that is <= 2004, I'm sorry Biff, that is incorrect it should be every record where the year 2004 falls between or is equal to the 2 dates, I've confused you again haven't I?.

The main problem I have now is the formula in A5 (copied across and down) is producing the wrong result. I know it is this part of the formula....

=IF(ROWS(A$5:A5)>$C$2,"",INDEX(Sheet1!A$2:A$13,SMALL(IF((YEAR(Sheet1!$D$2:$D$13)<=$A$2)+(YEAR(Sheet1!$E$2:$E$13)<=$A$2),ROW(Sheet1!$A$2:$A$13)-ROW(Sheet1!$A$2)+1),ROWS(A$5:A5))))

But I just can't figure out the correct structure.

My head hurts, suggestions please.

Ak
 
Upvote 0
Hi,

=IF(ROWS(A$5:A5)<=$C$2,INDEX(Sheet1!A$2:A$13,SMALL(IF(YEAR(Sheet1!$D$2:$D$13)<=$A$2,IF(YEAR(Sheet1!$E$2:$E$13)>=$A$2,ROW(Sheet1!$D$2:$D$13)-ROW(Sheet1!$D$2)+1)),ROWS(A$5:A5))),"")

HTH
 
Upvote 0
Akashwani,

I think that your formula is almost ok, only use * and not + and >= and not <=:

=IF(ROWS(A$5:A5)>$C$2,"",INDEX(Sheet1!A$2:A$13,SMALL(IF((YEAR(Sheet1!$D$2:$D$13)<=$A$2)*(YEAR(Sheet1!$E$2:$E$13)>=$A$2),ROW(Sheet1!$A$2:$A$13)-ROW(Sheet1!$A$2)+1),ROWS(A$5:A5))))


Markmzz
 
Last edited:
Upvote 0
Hi,

PERFECT, thank you very much chaps.
I think that I have spent far too long steering at these problems to be able to see or understand anything.

Thanks to you all for your contributions, much appreciated.

Ak
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,256
Members
452,901
Latest member
LisaGo

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