Multi Count Formula Needed

tmk0427

Board Regular
Joined
Dec 14, 2005
Messages
88
Office Version
  1. 365
Hi, AI can't help me so I turned to humans.

In the table below is as follows:

Column A is list of random names (last name, first name),
Column D is a list of specific codes
Columns F-AJ (columns I-Aj are hidden for sake of brevity) are days in a month 1-31 (in this case only days 1-3 show)
Column AK total of values of rows F-AJ (in this case only values total for columns F-H)
Column AL2:AL9 is where I want only unique names from column A. In this example, AL2 should result in Buck, Jim and AL3 should result in Smith, John.



ABCDEFGHAKALAMAN
NameMRNICDCPTDesc123TotalUnique NameDaysRT94668
2Buck, Jim RT94668 88824
3Buck, Jim RT94761 88824
4Buck, Jim RT94010 44 8
5Buck, Jim RT94060 44 8
6Smith, John RT94668 88 16
7Smith, John RT94761 88 16
8Smith, John RT94010 4 4
9Smith, John RT94060 4 4

Then in AM2 and down under the Days column, I need a formula that counts the cells in each row with the most values for F1:H9 but only for the unique name in AL2 and AL3. In this example, AM2 should result in 3 days for AL2 Buck, Jim and AM3 should result in 2 days for AL3 Smith, John.
The formula in column AM should look at F1:H9 and only count the most values in each row associated with Buck, Jim (AL2) and Smith, John (AL3). In this case, AM2 should see that F2-H2 and F3-H3 have 3 values total in each row and F4-H4 and F5-H5 only have 2. For AM3, rows F6-H6 and F7-H7 have 2 values total and rows F8-H8 and F9-H9 only have 1 value total.

Then in column AN under the RT94668 column I need a formula that sums the values F1:H9 that match column D "RT94668" for the Unique name in column AL. In this case, AN2 the formula should sum the row with CPT code RT94668 in column D under Buck, Jim which would be 24. In AN3, the formula would sum the row with CPT code RT94668 in column D under Smith, John which would be 16.

I hope this makes sense and I am open to other ways of configuring this table to make it easier to get my desired results.

Thank you in advance, humans.

Terence
 
Hello, humans strike back, i.e. try the following in AL2:

Excel Formula:
=LET(
n,A2:A9,
cpt,D2:D9,
t,F2:H9,
code,AN1,
u,UNIQUE(n),
d,MAP(u,LAMBDA(x,MAX(FILTER(BYROW(t,COUNTA),n=x)))),
c,MAP(u,LAMBDA(y,SUM(FILTER(t,(n=y)*(cpt=code))))),
HSTACK(u,d,c))
 
Upvote 0
Solution
Hello, humans strike back, i.e. try the following in AL2:

Excel Formula:
=LET(
n,A2:A9,
cpt,D2:D9,
t,F2:H9,
code,AN1,
u,UNIQUE(n),
d,MAP(u,LAMBDA(x,MAX(FILTER(BYROW(t,COUNTA),n=x)))),
c,MAP(u,LAMBDA(y,SUM(FILTER(t,(n=y)*(cpt=code))))),
HSTACK(u,d,c))
Wow. Humans are still necessary 🥲. That's an amazing formula. What would I need to do to tailor that formula to count the other cpt codes such as RT94761 or RT94010 etc? Thank you.
 
Upvote 0
Wow. Humans are still necessary 🥲. That's an amazing formula. What would I need to do to tailor that formula to count the other cpt codes such as RT94761 or RT94010 etc? Thank you.
In other words, if I wanted to add RT94761 to AO1 and so forth along the row.
 
Upvote 0
Many thanks for the feedback, try the following:

Excel Formula:
=LET(
n,A2:A9,
cpt,D2:D9,
t,F2:H9,
code,AN1:AO1,
u,UNIQUE(n),
d,MAP(u,LAMBDA(x,MAX(FILTER(BYROW(t,COUNTA),n=x)))),
c,DROP(REDUCE("",code,LAMBDA(a,b,HSTACK(a,MAP(u,LAMBDA(y,SUM(FILTER(t,(n=y)*(cpt=b)))))))),,1),
HSTACK(u,d,c))
 
Upvote 0
Many thanks for the feedback, try the following:

Excel Formula:
=LET(
n,A2:A9,
cpt,D2:D9,
t,F2:H9,
code,AN1:AO1,
u,UNIQUE(n),
d,MAP(u,LAMBDA(x,MAX(FILTER(BYROW(t,COUNTA),n=x)))),
c,DROP(REDUCE("",code,LAMBDA(a,b,HSTACK(a,MAP(u,LAMBDA(y,SUM(FILTER(t,(n=y)*(cpt=b)))))))),,1),
HSTACK(u,d,c))
Thank you.
 
Upvote 0
Ah, apologies, my omission; just the last part needs to adjusted, i.e.

Excel Formula:
IFERROR(HSTACK(u,d,c),0))
 
Upvote 0

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