COUNTIF? COUNTIFS? SUMIF? SUM(IF)[CO...AARRGH SOMEONE PLEASE HELP!

christopherjpurtell

New Member
Joined
Apr 10, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am trying to build a formula to count names that may repeat in multiple columns. I work for a dance studio, and I am tallying up our 5 and 10 year students with the first column being the enrollment from 2012, with each column representing the next consecutive year. I have tried to use =Countif(A2:M186, M2) but it is not producing the correct mathematical sum unless the names happen to be in the same row. I'm going crazy trying to figure this out....please help!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
How are you defining the "correct mathematical sum". What is in M2? Are you saying that columns A:M are student names for years 2012 through 2024. Are the same names on each row, or might the same names be staggered...found on different rows?
 
Upvote 0
Welcome to the MrExcel forum!

That should work (see below), but you have one issue in that the criterium (M2) is in the range being searched (A2:M186), so your count will be off by at least one.

Book2 (version 1).xlsb
ABCDEFGHIJKLMNO
12012201320142015201620172018201920202021202220232024Emma
2FredDanAmyBobCyndiAmyBobCyndiAmyCyndiBobDanCyndi15
3EmmaFredBobAmyAmyCyndiCyndiDanFredEmmaBobEmmaFred
4FredFredEmmaGinaGinaFredAmyBobAmyGinaEmmaAmyBob
5DanGinaAmyCyndiDanCyndiEmmaDanGinaEmmaFredFredAmy
6GinaCyndiGinaAmyBobAmyEmmaGinaEmmaGinaAmyEmmaBob
7DanGinaAmyEmmaBobGinaFredFredAmyCyndiDanBobEmma
8GinaBobFredCyndiDanGinaCyndiBobGinaAmyGinaDanFred
9CyndiEmmaEmmaDanBobFredEmmaGinaBobGinaBobBobDan
10CyndiBobGinaFredBobAmyFredFredDanAmyGinaDanAmy
Sheet2
Cell Formulas
RangeFormula
O2O2=COUNTIF(A2:M10,O1)
 
Upvote 0
How are you defining the "correct mathematical sum". What is in M2? Are you saying that columns A:M are student names for years 2012 through 2024. Are the same names on each row, or might the same names be staggered...found on different rows?
yes exactly,they are staggered
 
Upvote 0
Try this and fill down for each name.
Excel Formula:
=COUNTIF($B$2:$M$182,O2)
 
Upvote 0
Thank you...there are some issues. For example, your data set includes Bluestein ,jesse and Bluestein- ,Jessie in 2020 and 2023, respectively. They won't match...are they supposed to? You may need to do some data cleanup first.
 
Upvote 0
I just had a closer look at your data, and noticed that there are some differences in the way names are typed, which will affect your counts. For example, each of the people below have two different spellings entered.


Babini , Scarlet
Babini ,Scarlet
Baldwin , Nia
Baldwin ,Nia
Ball , Josie
Ball ,Josie
 
Upvote 0
What do the numbers mean after some of the names...for example, in 2023, Comeau-4? Some data cleanup is needed for the counts to work correctly.
 
Upvote 0
I mentioned some data cleanup would be in order. You could do this with VBA, Power Query, or a formula...a formula approach is shown here. I cleared all formatting in columns Q:AF, and then inserted this formula in R2:
Excel Formula:
=LET(all,B2:M183,n,MAP(all,LAMBDA(k,LET(s,SEQUENCE(LEN(k)),x,IF(k="","",TEXTJOIN("",TRUE,IF(ISERR(MID(k,s,1)+0),MID(k,s,1),""))),SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(x,".",", "),",",", "),"]","")," ,",",")),"-,",",")))), n)
The formula processes your master table using the MAP function to clean up extra spaces, replace periods with commas, eliminate spurious hyphens, eliminate numbers appearing in the text string, and ensure that commas separating names are of the form comma space. This creates a new master list that is nearly appropriate for counting individuals over the years, but there is still one problem. There are still cases where individuals' names are spelled differently. This new table spills across columns R:AC.

Then to address the spelling mismatches, a second formula is used in column AF...paste this in AF2:
Excel Formula:
=LET(a,TOCOL(R2#),SORT(UNIQUE(FILTER(a,a<>""))))
This formula creates a single list of unique, reformatted names that appear in the spilled table created in the previous step. Look through this list and identify any names that need to be corrected and made consistent. You'll need to search the original table in columns B:M for those names...make the changes in columns B:M to achieve consistency, and then re-review the list in column AF until no more name variations are found.

Once that is done, then the tidied-up and reformatted names appearing in R:AC can be used to perform the counting operation desired. If you want a count of everyone across all years, then the formula in AG...and if you want a count of only those enrolled in 2024, then the formula in AD. But note that the counts will not be correct until the spelling mismatches described in the previous paragraph are resolved.
Student Enrollment Lists 2024_rev.xlsx
QRSTUVWXYZAAABACADAEAFAG
1201220132014201520172018201920202021202220232024Counts 2024 ListFull list unique namesCounts Full List
2Adams, SophiaAdair, BrynAlvarez, LilianaAlvarez, LilianaAlabiso, MayaAllen, KaleighAzulay, IsabelleAdams, FinolaAdams, IsoldeAnderson, Ella3Adair, Bryn1
3Andrews, SabrinaAndrews, KarinaAzulay, IsabelleAnderson, EllaAnderson, EllaAstore, Jillian3Adams, Finola1
4Andrews, SabrinaAstore, JillianAstore, JillianAdams, Isolde1
5Adams, Sophia1
6Alabiso, Maya1
7Bell, MadisonBartholomew, LilyBanwarth, AdaBellabona, MiaBellabona, MiaBabini, ScarletBabini, ScarletBanano, avaBellabona, MiaBellabonna, MiaBall, JosieBoswell, Lila1Allen, Kaleigh1
8Breish, SydneyBell, MadisonBellabona, MiaBelliveau, ZoeBelliveau, ZoeBaldwin, NiaBaldwin, NiaBellabona, miaBernstein, JesseBernstein, JesseBernard, AveryBoucher, Corinne7Alvarez, Liliana2
MASTER
Cell Formulas
RangeFormula
R2:AC183R2=LET(all,B2:M183,n,MAP(all,LAMBDA(k,LET(s,SEQUENCE(LEN(k)),x,IF(k="","",TEXTJOIN("",TRUE,IF(ISERR(MID(k,s,1)+0),MID(k,s,1),""))),SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(x,".",", "),",",", "),"]","")," ,",",")),"-,",",")))), n)
AD2:AD183AD2=BYROW(TAKE(R2#,,-1),LAMBDA(r,IF(r="","",COUNTIF(R2#,r))))
AF2:AF477AF2=LET(a,TOCOL(R2#),SORT(UNIQUE(FILTER(a,a<>""))))
AG2:AG477AG2=BYROW(AF2#,LAMBDA(r,COUNTIF(R2#,r)))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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