Count unique numbers within range

BrutalLogiC

Active Member
Joined
Feb 26, 2006
Messages
274
Office Version
  1. 365
Platform
  1. Windows
help please, I'm trying to write a formula in the cells in yellow which will
1. in column D count the total number of unique POs ("purchasing documents") raised which fall under Group A (cell B5) and are within the range B7 to C7.
2. in column G sum the total of POs raised, it is ok to count the duplicate

The 'purchasing document' is the PO number on the master list sheet. There can be multiple rows for each PO number but I'm only interested in unique POs for the count.

You can see rows 37, 38, 39 and 40 have the same PO number so that will just count as one PO but I still want the total sum of all 4 rows to be included... hope that makes sense.


Book1
BCDG
5Group A
6PO Range From:PO Range To:No. of POs raised in calendar yearSum of POs raised
7-20,000
820,001250,000
9250,001100,000,000
10
110-
12
13Group B
14PO Range From:PO Range To:No. of POs raised in calendar yearSum of POs raised
15-150,000
16150,001300,000
17300,0011,000,000
181,000,001100,000,000
190-
DOA



Book1
BCH
3EntityPurchasing DocumentNet Order Value
4Group A130000826696.00
37Group B130000826784.00
38Group B1300008267168.00
39Group B1300008267165.00
40Group B1300008267165.00
41Group C13000082689,500.00
42Group D1300008269216.00
81Group B1300008271360.00
82Group B1300008271220.00
83Group B1300008271280.00
84Group B1300008271360.00
85Group A1300008272171.00
86Group A130000827280.00
87Group D1300008273294.00
16710Group A40000002991,665.00
16711Group A40000002991,665.00
16712Group B400000030035,100.00
16713Group D40000003015,895.00
Master list
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Your PO ranges did not seem to match up to your PO's on the master list, so I made some changes in the example below.

Formula in D5 is an array formula and must be entered with CTRL-SHIFT-ENTER. Drag formula down as needed.
Excel Workbook
ABCDE
1Group A
2PO RangePO RangeNo. of POs raised in calendar yearSum of POs raised
3
4From:To:
5100000000015000000002347
61500000001400000000000
74000000001500000000113330
DOA
Excel Workbook
ABCD
1EntityPurchasing DocumentNet Order Value
2Group A1,300,008,26696.00
3Group B130000826784.00
4Group B1300008267168.00
5Group B1300008267165.00
6Group B1300008267165.00
7Group C13000082689,500.00
8Group D1300008269216.00
9Group B1300008271360.00
10Group B1300008271220.00
11Group B1300008271280.00
12Group B1300008271360.00
13Group A1300008272171.00
14Group A130000827280.00
15Group D1300008273294.00
16Group A40000002991,665.00
17Group A40000002991,665.00
18Group B4,000,000,30035,100.00
19Group D40000003015,895.00
Master list
 
Upvote 0
Thanks Ahoy I used:

{=SUM(IF(FREQUENCY(IF('Master list'!$B$4:$B$20000=$B$5,IF('Master list'!$H$4:$H$20000>=$B7,IF('Master list'!$H$4:$H$20000<=$C7,MATCH('Master list'!$C$4:$C$20000,'Master list'!$C$4:$C$20000,0)))),ROW('Master list'!$C$4:$C$20000)-ROW('Master list'!$C$4)+1),1))}

which worked perfect but it is soooo slow on my laptop, I wonder if there is a faster formula to produce same result?
 
Upvote 0
To not use a matrix formula, you can create an auxiliary column in the "Master list" sheet to count the unique documents.

(I guess the values ​​in your range from: to: are amounts).


Then on your sheet "Master list" put the following formula in I4 and the copies down.

<table style="font-family:Arial; font-size:12pt; border-style: groove ;border-color:#0000FF;background-color:#fffcf9; color:#000000; "><tr><td ><b>Master list</b></td></tr></table><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:25.66px;" /><col style="width:54.18px;" /><col style="width:134.97px;" /><col style="width:102.65px;" /><col style="width:70.34px;" /></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><td >H</td><td >I</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td > </td><td style="background-color:#92d050; font-weight:bold; text-align:center; ">Entity</td><td style="background-color:#92d050; font-weight:bold; text-align:center; ">Purchasing Document</td><td style="background-color:#92d050; font-weight:bold; text-align:center; ">Net Order Value</td><td style="background-color:#92d050; font-weight:bold; text-align:center; ">Unique</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td > </td><td >Group A</td><td style="text-align:right; ">1300008266</td><td style="text-align:right; ">96.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td > </td><td >Group B</td><td style="text-align:right; ">1300008267</td><td style="text-align:right; ">84.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td > </td><td >Group B</td><td style="text-align:right; ">1300008267</td><td style="text-align:right; ">168.00</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 > </td><td >Group B</td><td style="text-align:right; ">1300008267</td><td style="text-align:right; ">165.00</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 > </td><td >Group B</td><td style="text-align:right; ">1300008267</td><td style="text-align:right; ">165.00</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 > </td><td >Group C</td><td style="text-align:right; ">1300008268</td><td style="text-align:right; ">9,500.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td > </td><td >Group D</td><td style="text-align:right; ">1300008269</td><td style="text-align:right; ">216.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td > </td><td >Group B</td><td style="text-align:right; ">1300008271</td><td style="text-align:right; ">360.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >12</td><td > </td><td >Group B</td><td style="text-align:right; ">1300008271</td><td style="text-align:right; ">220.00</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 > </td><td >Group B</td><td style="text-align:right; ">1300008271</td><td style="text-align:right; ">280.00</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 > </td><td >Group B</td><td style="text-align:right; ">1300008271</td><td style="text-align:right; ">360.00</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 > </td><td >Group A</td><td style="text-align:right; ">1300008272</td><td style="text-align:right; ">171.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >16</td><td > </td><td >Group A</td><td style="text-align:right; ">1300008272</td><td style="text-align:right; ">80.00</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 > </td><td >Group D</td><td style="text-align:right; ">1300008273</td><td style="text-align:right; ">294.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >18</td><td > </td><td >Group A</td><td style="text-align:right; ">4000000299</td><td style="text-align:right; ">1,665.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >19</td><td > </td><td >Group A</td><td style="text-align:right; ">4000000299</td><td style="text-align:right; ">1,665.00</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 > </td><td >Group B</td><td style="text-align:right; ">4000000300</td><td style="text-align:right; ">35,100.00</td><td style="text-align:right; ">1</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >21</td><td > </td><td >Group D</td><td style="text-align:right; ">4000000301</td><td style="text-align:right; ">5,895.00</td><td style="text-align:right; ">1</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 >I4</td><td >=IF(COUNTIFS($B$4:B4,B4,$C$4:C4,C4)=1,1,0)</td></tr></table></td></tr></table> <br /><br />


<table style="font-family:Arial; font-size:12pt; border-style: groove ;border-color:#0000FF;background-color:#fffcf9; color:#000000; "><tr><td ><b>sheet DOA</b></td></tr></table><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:38.02px;" /><col style="width:69.39px;" /><col style="width:84.59px;" /><col style="width:227.17px;" /><col style="width:140.67px;" /></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><td >D</td><td >E</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td > </td><td > </td><td > </td><td > </td><td > </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td > </td><td style="background-color:#ffc000; color:#333333; font-weight:bold; font-family:Verdana; font-size:9pt; ">Group A</td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; "> </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td > </td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; ">PO Range</td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; ">PO Range</td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; ">No. of POs raised in calendar year</td><td style="background-color:#ffc000; color:#333333; font-family:Verdana; font-size:9pt; ">Sum of POs raised</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">0</td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">20,000</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">3</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">3,677.00</td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">20,001</td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">250,000</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">0</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; "> </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">250,001</td><td style="color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">100,000,000</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">0</td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; "> </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td > </td><td style="color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#ffff00; color:#333333; font-family:Verdana; font-size:9pt; "> </td></tr><tr style="height:19px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td > </td><td style="background-color:#d9d9d9; color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#d9d9d9; color:#333333; font-family:Verdana; font-size:9pt; "> </td><td style="background-color:#d9d9d9; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">0</td><td style="background-color:#d9d9d9; color:#333333; font-family:Verdana; font-size:9pt; text-align:right; ">-</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 >D7</td><td >=COUNTIFS('Master list'!$B$4:$B$21,B5,'Master list'!$H$4:$H$21,">="&$B7,'Master list'!$H$4:$H$21,"<="&$C7,'Master list'!$I$4:$I$21,1)</td></tr><tr><td >E7</td><td >=SUMIFS('Master list'!$H$4:$H$21,'Master list'!$B$4:$B$21,$B$5,'Master list'!$H$4:$H$21,">=" & $B7,'Master list'!$H$4:$H$21,"<="&C7)</td></tr></table></td></tr></table> <br /><br />
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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