Formula to Count Unique Distinct Values That Meet Multiple Criteria

Gomesy

New Member
Joined
Oct 16, 2005
Messages
31
Working on another project for work where I need to look at over 25K rows of data and perform a count of the Unique Order Numbers that made up our Web Orders in each of the last 4 years. My file has 2 tabs. One is labeled "Sales History" and the other is called "Metrics". The "Metrics" tab is where all of my information needs to summarize.

I tried using an array combination of Sumif and Countifs formulas but can't quite seem to get it to work.

Here is a sampling of my data found on the "Sales History" tab:


[TABLE="width: 182"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Order #[/TD]
[TD]Year[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]117524122[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]117661819[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]118358926[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]118682343[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]118700680[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]119543065[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]119920626[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]121099398[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]123782132[/TD]
[TD]2016[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]127465017[/TD]
[TD]2017[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]302163150[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]302163150[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]302460485[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]502324656[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502326151[/TD]
[TD]2014[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]502410851[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502416849[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502460540[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502463371[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502562568[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502576243[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]502625989[/TD]
[TD]2015[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]503172589[/TD]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]503725656[/TD]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]503816214[/TD]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]503816214[/TD]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323 [/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
[TR]
[TD]W106260323[/TD]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[/TR]
</tbody>[/TABLE]

Can someone help me please?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:
This is an array formula and must be entered with CTRL-SHIFT-ENTER.

Change ranges to match your data and drag formula down as needed.
Excel Workbook
AB
1YearCount Web Orders
220148
320150
420161
520172
Metrics
Excel Workbook
ABC
1Order #YearWeb Orders
21175241222014
31176618192014
41183589262014
51186823432014
61187006802014
71195430652014
81199206262015
91210993982015
101210993982015
111210993982015
121210993982015
131210993982015
141210993982015
151210993982015
161237821322016
171274650172017
183021631502015
193021631502015
203024604852015
215023246562014Web Orders
225023261512014
235024108512014Web Orders
245024168492014Web Orders
255024605402014Web Orders
265024633712014Web Orders
275025625682014Web Orders
285025762432014Web Orders
295026259892015
305031725892016Web Orders
315037256562017Web Orders
325038162142017Web Orders
335038162142017Web Orders
34W1062603232014Web Orders
35W1062603232014Web Orders
36W1062603232014Web Orders
37W1062603232014Web Orders
38W1062603232014Web Orders
39W1062603232014Web Orders
40W1062603232014Web Orders
41W1062603232014Web Orders
42W1062603232014Web Orders
43W1062603232014Web Orders
44W1062603232014Web Orders
45W1062603232014Web Orders
46W1062603232014Web Orders
47W1062603232014Web Orders
48W1062603232014Web Orders
Sales History
 
Upvote 0
Maybe:


Excel 2012
EFGH
12014201520162017
28012
Sheet1
Cell Formulas
RangeFormula
E2{=SUM(SIGN(FREQUENCY(IF($B$2:$B$48=E1,IF($C$2:$C$48="Web Orders",MATCH($A$2:$A$48,$A$2:$A$48,0))),ROW($A$2:$A$48)-ROW($A$2)+1)))}
Press CTRL+SHIFT+ENTER to enter array formulas.


I was born in Savannah, but I haven't been back in many, many years!
 
Upvote 0
This one worked great! Thank you so much. I have another challenge. I added a couple more fields to the database. This time I need to find the Unique and Distinct # of units (guest rooms) that correspond to Unique Customers who placed a Web Order in 2014. Same two worksheets as before. I tried just adding the additional fields of customer # and units to the equation but didn't get a valid answer. How would you tweak the formula you gave me to solve this puzzle?

[TABLE="width: 234"]
<colgroup><col><col><col span="2"></colgroup><tbody>[TR]
[TD]Year[/TD]
[TD]Web Orders[/TD]
[TD]HDS Account #[/TD]
[TD]Units[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]4887227[/TD]
[TD]79[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]4887227[/TD]
[TD]79[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[TD]1939643[/TD]
[TD]94[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[TD]1939643[/TD]
[TD]94[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[TD]1939643[/TD]
[TD]94[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[TD]1939643[/TD]
[TD]94[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD]Web Orders[/TD]
[TD]1939643[/TD]
[TD]94[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]5909972[/TD]
[TD]112[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]5909972[/TD]
[TD]112[/TD]
[/TR]
[TR]
[TD]2014[/TD]
[TD][/TD]
[TD]2068909[/TD]
[TD]86[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]3329331[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]3329331[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]3329331[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]3329331[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]3329331[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD]Web Orders[/TD]
[TD]6129968[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD]Web Orders[/TD]
[TD]6129968[/TD]
[TD]85[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]6151214[/TD]
[TD]115[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]6151214[/TD]
[TD]115[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]6151214[/TD]
[TD]115[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]6147656[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2015[/TD]
[TD][/TD]
[TD]6147656[/TD]
[TD]83[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]2066665[/TD]
[TD]68[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]2066665[/TD]
[TD]68[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]2066665[/TD]
[TD]68[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[TD]14148293 [/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]14354110[/TD]
[TD]78[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]14354110[/TD]
[TD]78[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]14354110[/TD]
[TD]78[/TD]
[/TR]
[TR]
[TD]2016[/TD]
[TD][/TD]
[TD]14354110[/TD]
[TD]78[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD]Web Orders[/TD]
[TD]14148293[/TD]
[TD]106[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
[TR]
[TD]2017[/TD]
[TD][/TD]
[TD]12560316[/TD]
[TD]80[/TD]
[/TR]
</tbody>[/TABLE]

Thanks!
 
Upvote 0
Wow Eric! This one works too. We just moved to Savannah from Chicago 3 months ago. We live on one of the barrier islands (Skidaway). It's like a little piece of heaven. Thanks for responding to my request. Maybe you'd care to take a look at my 2nd request. It just adds another search element than the first one.

Thanks for helping me out!

Rick
 
Upvote 0
Yes 94 is the single result I am looking for. If you look at the data you will see that there is only one customer that placed Web Orders in 2014 and that one customer's hotel has 94 units (rooms). My data set has 25K rows of data. A formula to extract this information would be helpful.

Thank you,

Rick
 
Upvote 0
Yes 94 is the single result I am looking for. If you look at the data you will see that there is only one customer that placed Web Orders in 2014 and that one customer's hotel has 94 units (rooms). My data set has 25K rows of data. A formula to extract this information would be helpful.

Thank you,

Rick

A2:A48 is named as Year, B2:B48 as WebOrders, C2:C48 as Account, and D2:D48 as Units in what follows.

In G1 control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(Year=2014,IF(WebOrders="web orders",IF(ISNUMBER(MATCH(Account,IF(Year=2014,IF(WebOrders="web orders",Account)),0)),Units))),Units),1))

In G2 control+shift+enter, not just enter, and copy down:

=IF(ROWS($G$2:G2)>$G$1,"",INDEX(Units,SMALL(IF(FREQUENCY(IF(Year=2014,IF(WebOrders="web orders",IF(ISNUMBER(MATCH(Account,IF(Year=2014,IF(WebOrders="web orders",Account)),0)),MATCH(Units,Units,0)))),ROW(Units)-ROW(INDEX(Units,1,1))+1),ROW(Units)-ROW(INDEX(Units,1,1))+1),ROWS($G$2:G2))))
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
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