Formula to Calculate Complex Count

masouder

Board Regular
Joined
Jul 5, 2013
Messages
111
Office Version
  1. 2013
Platform
  1. Windows
I have a somewhat complex count to complete. I need to count the number of Accounts that have more than one Carrier where the Agent is Sally and the Date is Aug 1. In the example below the formula should return 1: only ACME Hardware has more than one Carrier.

Any help is appreciated.

Excel Question.xlsx
ABCD
1AccountCarrierAgentDate
2ACME HardwareCalChoiceSally1-Aug
3ACME HardwareCovered CaliforniaSally1-Aug
4ACME HardwareChoice BuilderSally1-Aug
5ACME HardwareChoice BuilderSally1-Aug
6ACME HardwareChoice BuilderSally1-Aug
7ACME HardwareChoice BuilderSally1-Aug
8ACME HardwareBeam DentalSally1-Aug
9ACME HardwareBeam DentalSally1-Aug
10South Street MarketBlue ShieldSally1-Aug
11South Street MarketBlue ShieldSally1-Aug
12South Street MarketBlue ShieldSally1-Aug
13South Street MarketBlue ShieldSally1-Aug
14Mid City DrugstoreMetLifeSally1-Aug
15Mid City DrugstoreMetLifeSally1-Aug
16Mid City DrugstoreMetLifeSally1-Aug
17Mid City DrugstoreMetLifeSally1-Aug
18Mid City DrugstoreMetLifeSally1-Aug
19Mid City DrugstoreMetLifeSally1-Aug
20Mid City DrugstoreMetLifeSally1-Aug
21Mid City DrugstoreMetLifeSally1-Aug
22Mid City DrugstoreMetLifeSally1-Aug
Sheet1 (2)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How about:

Book1 (version 1).xlsb
ABCDEFGHI
1AccountCarrierAgentDateAgentDate# of Accounts with over 1 carrier
2ACME HardwareCalChoiceSally8/1/2021Sally8/1/20211
3ACME HardwareCovered CaliforniaSally8/1/2021
4ACME HardwareChoice BuilderSally8/1/2021
5ACME HardwareChoice BuilderSally8/1/2021
6ACME HardwareChoice BuilderSally8/1/2021
7ACME HardwareChoice BuilderSally8/1/2021
8ACME HardwareBeam DentalSally8/1/2021
9ACME HardwareBeam DentalSally8/1/2021
10South Street MarketBlue ShieldSally8/1/2021
11South Street MarketBlue ShieldSally8/1/2021
12South Street MarketBlue ShieldSally8/1/2021
13South Street MarketBlue ShieldSally8/1/2021
14Mid City DrugstoreMetLifeSally8/1/2021
15Mid City DrugstoreMetLifeSally8/1/2021
16Mid City DrugstoreMetLifeSally8/1/2021
17Mid City DrugstoreMetLifeSally8/1/2021
18Mid City DrugstoreMetLifeSally8/1/2021
19Mid City DrugstoreMetLifeSally8/1/2021
20Mid City DrugstoreMetLifeSally8/1/2021
21Mid City DrugstoreMetLifeSally8/1/2021
22Mid City DrugstoreMetLifeSally8/1/2021
Sheet12
Cell Formulas
RangeFormula
I2I2=SUMPRODUCT(--(FREQUENCY(IF(C2:C22=G2,IF(D2:D22=H2,IF(MATCH(A2:A22&"|"&B2:B22,A2:A22&"|"&B2:B22,0)=ROW(A2:A22)-ROW(A2)+1,MATCH(A2:A22,A2:A22,0)))),MATCH(A2:A22,A2:A22,0))>1))
 
Upvote 0
Solution
That appears to work. Thank you!
I have re-marked the "Solution".
In marking the solution, please mark the actual post that contains the solution (and not your post acknowldeging that someone has posted the correct solution).

Thanks
 
Upvote 0
Actually, I discovered that sometimes the suggested formula works correctly and sometimes it does not. In the example below the formula should return 2 because ACME Hardware and Mid City Drugstore have more than one Carrier. If I change some of the Carriers for Mid City or rearrange the order of how the carriers appear then it sometimes works, but I cannot detect a pattern.

Any further help is greatly appreciated.

Excel Question.xlsx
ABCDEFG
1AccountCarrierAgentDate
2ACME HardwareCalChoiceSally1-AugSally1-Aug
3ACME HardwareCovered CaliforniaSally1-Aug
4ACME HardwareChoice BuilderSally1-Aug1
5ACME HardwareChoice BuilderSally1-Aug
6ACME HardwareChoice BuilderSally1-Aug
7ACME HardwareChoice BuilderSally1-Aug
8ACME HardwareBeam DentalSally1-Aug
9ACME HardwareBeam DentalSally1-Aug
10South Street MarketBlue ShieldSally1-Aug
12South Street MarketBlue ShieldSally1-Aug
13South Street MarketBlue ShieldSally1-Aug
17Mid City DrugstoreBlue ShieldSally1-Aug
19Mid City DrugstoreMetLifeSally1-Aug
20Mid City DrugstoreBlue ShieldSally1-Aug
21Mid City DrugstoreMetLifeSally1-Aug
22Mid City DrugstoreMetLifeSally1-Aug
Sheet1 (2)
Cell Formulas
RangeFormula
F4F4=SUMPRODUCT(--(FREQUENCY(IF(C2:C22=F2,IF(D2:D22=G2,IF(MATCH(A2:A22&"|"&B2:B22,A2:A22&"|"&B2:B22,0)=ROW(A2:A22)-ROW(A2)+1,MATCH(A2:A22,A2:A22,0)))),MATCH(A2:A22,A2:A22,0))>1))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
What version of Excel are you using? (It would help if you could update your user profile with that information.) I copied your mini-sheet to Excel 365, and it worked (got an answer of 2) immediately. I then copied it to Excel 2016, and it worked once I added the CSE. I even tried Excel 2000, but just got an error.

I thought the blank/hidden rows might have been an issue, so I played around with that for a bit, to no avail. On my 2016 version, I even got a result of 3 for the same data. Running it through Evaluate Formula showed it worked perfectly up to the last step, then gave a 3, making no sense at all.

In any case, try this variation, it works for me in 2016. Since you have to use CSE anyway, I used SUM instead of SUMPRODUCT. But the main change is changing the second array from MATCH to ROW:

Excel Formula:
=SUM(--(FREQUENCY(IF(C2:C22=F2,IF(D2:D22=G2,IF(MATCH(A2:A22&"|"&B2:B22,A2:A22&"|"&B2:B22,0)=ROW(A2:A22)-ROW(A2)+1,MATCH(A2:A22,A2:A22,0)))),ROW(A2:A22)-ROW(A2)+1)>1))
 
Upvote 0
I am using Excel 2013. (I work with many clients, so I tend to stay a bit behind on version so that I don't create something that they cannot use.)

I tried the new formula, thank you, and got the same result, 1. Note that the issue appears to be related to the number of different Carriers. When I add a third carrier to Mid City it calculates 2, as expected. Note that in a larger example, I still cannot find any consistency other than for some Accounts if I add another Carrier or change the order of the Carriers then it works.

What is CSE?
 
Upvote 0
I tried the formula with Excel 2010. I deleted the blank rows and Array Entered the formula CSE Control Shift Enter; the result was 2.
N.B. Excel will add the curly brackets for Array Formula.

T202109a.xlsm
F
42
4b
Cell Formulas
RangeFormula
F4F4=SUMPRODUCT(--(FREQUENCY(IF(C2:C17=F2,IF(D2:D17=G2,IF(MATCH(A2:A17&"|"&B2:B17,A2:A17&"|"&B2:B17,0)=ROW(A2:A17)-ROW(A2)+1,MATCH(A2:A17,A2:A17,0)))),MATCH(A2:A17,A2:A17,0))>1))
Press CTRL+SHIFT+ENTER to enter array formulas.

I may try with 365 later.
 
Upvote 0
Ahh, Ctrl+Shift+Enter. I knew to press that for arrays, just didn't know what CSE meant.

What do you mean you deleted the blank rows?
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,047
Members
448,940
Latest member
mdusw

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