Countifs ignoring duplicate dates in specific range

-=NO=-

New Member
Joined
May 9, 2011
Messages
27
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello Guys;

I do appreciate your help to count the number of codes in each year ignoring the duplicates dates in this selected year

I used that formula but it's not ignoring duplicates

Code:
=COUNTIFS(Data!$B$2:$B$10000,B2,Data!$A$2:$A$10000,">=1/1/2012",Data!$A$2:$A$10000,"<1/1/2013")

A (Date)B (Code)
29-06-091NACHLRD
29-06-091HYDRCAC
20-06-101ACTCAC
29-06-121MTLPRBNB
29-06-091BNZYLALC
29-06-091NAEDTA
29-06-091PEG400
29-06-091ETHNL96
29-06-091DMNNTL
02-06-131NACHLRD
29-06-091NAACTTHD
29-06-091ETHNL96
30-06-092AMVAR05TR
12-07-121MTLPRBNB
12-07-131NAMTBSLF
16-07-141NACHLRD
02-08-151LCOVNCA
10-08-092AMVAR05TR
10-08-092AMVAR05TR
10-08-192AMVAR05TR

<colgroup><col><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
What is the result you expect?
2-2
2-1
1-2
1-1
1-0
0-1


<table border="1" cellspacing="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:91.25px;" /><col style="width:102.65px;" /><col style="width:76.04px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >A (Date)</td><td >B (Code)</td><td >RESULT</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td style="text-align:right; ">29/06/2009</td><td >1NACHLRD</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td style="text-align:right; ">29/06/2009</td><td >1HYDRCAC</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td style="text-align:right; ">20/06/2010</td><td >1ACTCAC</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">29/06/2012</td><td >1MTLPRBNB</td><td style="text-align:right; ">2</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="text-align:right; ">29/06/2009</td><td >1BNZYLALC</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="text-align:right; ">29/06/2009</td><td >1NAEDTA</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td style="text-align:right; ">29/06/2009</td><td >1PEG400</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td style="text-align:right; ">29/06/2009</td><td >1ETHNL96</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td style="text-align:right; ">29/06/2009</td><td >1DMNNTL</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td style="text-align:right; ">02/06/2013</td><td >1NACHLRD</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >12</td><td style="text-align:right; ">29/06/2009</td><td >1NAACTTHD</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >13</td><td style="text-align:right; ">29/06/2009</td><td >1ETHNL96</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >14</td><td style="text-align:right; ">30/06/2009</td><td >2AMVAR05TR</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >15</td><td style="text-align:right; ">12/07/2012</td><td >1MTLPRBNB</td><td style="text-align:right; ">2</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >16</td><td style="text-align:right; ">12/07/2013</td><td >1NAMTBSLF</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >17</td><td style="text-align:right; ">16/07/2014</td><td >1NACHLRD</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >18</td><td style="text-align:right; ">02/08/2015</td><td >1LCOVNCA</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >19</td><td style="text-align:right; ">10/08/2009</td><td >2AMVAR05TR</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >20</td><td style="text-align:right; ">10/08/2009</td><td >2AMVAR05TR</td><td style="text-align:right; ">0</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >21</td><td style="text-align:right; ">10/08/2019</td><td >2AMVAR05TR</td><td style="text-align:right; ">0</td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b></b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >C2</td><td >=COUNTIFS(Data!$B$2:$B$10000,B2,Data!$A$2:$A$10000,">=1/1/2012",Data!$A$2:$A$10000,"<1/1/2013")</td></tr></table></td></tr></table>
 
Upvote 0
Thanks Dante

If we get that code "2AMVAR05TR" as an example, so i expect the results as below in red

What is the result you expect?
2-2
2-1
1-2
1-1
1-0
0-1


ABC
1A (Date)B (Code)RESULT
229/06/20091NACHLRD0
329/06/20091HYDRCAC0
420/06/20101ACTCAC0
529/06/20121MTLPRBNB2
629/06/20091BNZYLALC0
729/06/20091NAEDTA0
829/06/20091PEG4000
929/06/20091ETHNL960
1029/06/20091DMNNTL0
1102/06/20131NACHLRD0
1229/06/20091NAACTTHD0
1329/06/20091ETHNL960
1430/06/20092AMVAR05TR2
1512/07/20121MTLPRBNB2
1612/07/20131NAMTBSLF0
1716/07/20141NACHLRD0
1802/08/20151LCOVNCA0
1910/08/20092AMVAR05TR2
2010/08/20092AMVAR05TR
2110/08/20192AMVAR05TR1

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:91.25px;"><col style="width:102.65px;"><col style="width:76.04px;"></colgroup><tbody>
</tbody>

CellFormula
C2=COUNTIFS(Data!$B$2:$B$10000,B2,Data!$A$2:$A$10000,">=1/1/2012",Data!$A$2:$A$10000,"<1/1/2013")

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
Thanks Dante

If we get that code "2AMVAR05TR" as an example, so i expect the results as below in red

I do not find logic in your answer, you could explain why those results.
Note, I suppose it is typo error, in the formula of your example you have 2012 and in the selected examples you have 2009.
 
Upvote 0
Sorry Dante for mis understanding

I meant that the formula that i want will represent these results.
Please ignore my formula, it represents a false values
 
Upvote 0
Hi,

I have put the formula for count if without dates, please feel free to modify that part, hoping rest works per your requirement:


Book1
ABC
1A (Date)B (Code)Count
26/29/20091NACHLRD1
36/29/20091HYDRCAC1
46/20/20101ACTCAC1
56/29/20121MTLPRBNB1
66/29/20091BNZYLALC1
76/29/20091NAEDTA1
86/29/20091PEG4001
96/29/20091ETHNL962
106/29/20091DMNNTL1
116/2/20131NACHLRD1
126/29/20091NAACTTHD1
136/29/20091ETHNL96
146/30/20092AMVAR05TR1
157/12/20121MTLPRBNB1
167/12/20131NAMTBSLF1
177/16/20141NACHLRD1
187/12/20121LCOVNCA1
198/10/20092AMVAR05TR2
208/10/20092AMVAR05TR
218/10/20192AMVAR05TR1
Sheet4
Cell Formulas
RangeFormula
C2=IF(SUMPRODUCT(--($A$1:A1&$B$1:B1=A2&B2))=0,COUNTIFS($A$2:$A$21,A2,$B$2:$B$21,$B2),"")
 
Upvote 0
Sorry Dante for mis understanding

I meant that the formula that i want will represent these results.
Please ignore my formula, it represents a false values

I understand about the formula.
But I was referring to your results in red.
You have years of 2009 and 2019.
 
Upvote 0
Thanks Aryatect

But I need formula to count depending on year (2012, 2013, etc.)
 
Upvote 0
OK Dante.

I have two sheets, the second is the target sheet, what i need is a formula in each cell to count the no. of code that repeated in specific year such as 2012

Code2012201320142015
1DCTXLTRHD11
1DXRBCNHCL112
1ETPSD11

<tbody>
</tbody>

the first one, is containing the data

CodeDate
1DXRBCNHCL2/1/2013
1DCTXLTRHD1/5/2012
1DXRBCNHCL2/1/2012
1ETPSD10/7/2015
1DCTXLTRHD1/5/2012
1ETPSD2/1/2012
1ETPSD2/1/2012
1DXRBCNHCL2/1/2015
1DCTXLTRHD1/9/2015
1DXRBCNHCL22/10/2015

<tbody>
</tbody>

I hope this is clear now, and thanks again
 
Upvote 0
A
B
C
D
1
CodeDate
2
1DXRBCNHCL
2/1/2013​
Sheet1
3
1DCTXLTRHD
1/5/2012​
4
1DXRBCNHCL
2/1/2012​
5
1ETPSD
10/7/2015​
6
1DCTXLTRHD
1/5/2012​
7
1ETPSD
2/1/2012​
8
1ETPSD
2/1/2012​
9
1DXRBCNHCL
2/1/2015​
10
1DCTXLTRHD
1/9/2015​
11
1DXRBCNHCL
10/22/2015​

<tbody>
</tbody>


A
B
C
D
E
F
G
1
Code
2012​
2013​
2014​
2015​
Sheet 2
2
1DCTXLTRHD
1​
0​
0​
1​
3
1DXRBCNHCL
1​
1​
0​
2​
4
1ETPSD
1​
0​
0​
1​

<tbody>
</tbody>


B2=IF(AND(Sheet2!$A2<>"",Sheet2!B$1<>""),SUM(IF(FREQUENCY(IF(Sheet1!$A$2:$A$11=Sheet2!$A2,IF(YEAR(Sheet1!$B$2:$B$11)=Sheet2!B$1,Sheet1!$B$2:$B$11)),Sheet1!$B$2:$B$11),1)),"")


Control+Shift+Enter


copy across and down

for hide 0

custom format
[=0]""

 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
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