More efficient than counting using SUMPRODUCT (date criteria)

kcmuppet

Active Member
Joined
Nov 2, 2005
Messages
437
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I've got a 20,000+ row table in which I'm trying to add a column that keeps a count with criteria, but my COUNTIFS attempt didn't work with Years of dates in the criteria...

Excel Formula:
=COUNTIFS(YEAR([Visit Date]),YEAR([@[Visit Date]]),[Visit Type],"Initial",[Patient],[@Patient])

...so I used the following sumproduct, but its not efficient (i.e. causes excel to run slowly). Is there a way to use something that will run more quickly?

Excel Formula:
=SUMPRODUCT(--(YEAR([Visit Date])=YEAR([@[Visit Date]])),--([Visit Type]="Initial"),--([Patient]=[@Patient]))
 

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)
You could try something like:

Excel Formula:
=COUNTIFS([Visit Date],">="&DATE(YEAR([@[Visit Date]]),1,1),[Visit Date],"<="&DATE(YEAR([@[Visit Date]]),12,31),[Visit Type],"Initial",[Patient],[@Patient])
but as soon as you get into multiple criteria you are going to see some performance hit, especially if you have a large table.
 
Upvote 0
You could try something like:

Excel Formula:
=COUNTIFS([Visit Date],">="&DATE(YEAR([@[Visit Date]]),1,1),[Visit Date],"<="&DATE(YEAR([@[Visit Date]]),12,31),[Visit Type],"Initial",[Patient],[@Patient])
but as soon as you get into multiple criteria you are going to see some performance hit, especially if you have a large table.
Thanks this is considerably quicker
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,172
Members
449,071
Latest member
cdnMech

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