textsplit() + mode.mult() = My happiness (maybe? finally?)

bksbksbks

New Member
Joined
Nov 18, 2024
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
  3. Web
In the data below, the grouping data is generated in a CSV, then formulated to output the grouping ID (A) and the jobs within that grouping (B). I'm trying to find the most common job within that grouping, which will sometimes have a single result in the CSV (like Grouping1) or multiple results (like Grouping2).
Book1
ABCD
1DataDesired Result
2idoutputGrouping1Grouping2
3Grouping1CIO|DIRECTOR OF IS|NETWORK MGRCIO|DIRECTOR OF IS|NETWORK MGRPump Deli Clerk|PUMP MGR
4Grouping2Pump Deli Clerk|PUMP MGR|PUMP DIRECTOR
5Grouping2PUMP MGR|PUMP FOOD COURT AST MGR|PUMP FOOD COURT ASSOCIATE|PUMP SALES ASSOCIATE|PUMP MAINTENANCE CLERK|STORE ASSOC UNDER 19|PUMP 1ST ASST MGR|Pump Deli Clerk
Sheet1

In Grouping1 there is only result, so the three jobs within that result are each the most common. In Grouping2 there are two results, so counting all of the jobs between the results finds that Pump Deli Clerk and PUMP MGR both occur twice, making them the most common results.

I have attempted several variations of mode.mult(), index(), match(), and everything else I can think of, but nothing wants to play well with textsplit() to pull out the job titles. How can I find the most common job within each grouping?

As always, thanks to all of the dedicated volunteers who spend their time helping out everyone on their Excel learning journeys!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try:
Book1
ABCD
1DataDesired Result
2idoutputGrouping1Grouping2
3Grouping1CIO|DIRECTOR OF IS|NETWORK MGRCIO|DIRECTOR OF IS|NETWORK MGRPump Deli Clerk|PUMP MGR
4Grouping2Pump Deli Clerk|PUMP MGR|PUMP DIRECTOR
5Grouping2PUMP MGR|PUMP FOOD COURT AST MGR|PUMP FOOD COURT ASSOCIATE|PUMP SALES ASSOCIATE|PUMP MAINTENANCE CLERK|STORE ASSOC UNDER 19|PUMP 1ST ASST MGR|Pump Deli Clerk
Sheet3
Cell Formulas
RangeFormula
C3:D3C3=LET(t,TEXTSPLIT(TEXTJOIN("|",,FILTER($B$3:$B$5,$A$3:$A$5=C2)),,"|"),g,GROUPBY(t,t,COUNTA,,0),TEXTJOIN("|",,FILTER(INDEX(g,,1),INDEX(g,,2)=MAX(INDEX(g,,2)))))
 
Upvote 0
Try:
Book1
ABCD
1DataDesired Result
2idoutputGrouping1Grouping2
3Grouping1CIO|DIRECTOR OF IS|NETWORK MGRCIO|DIRECTOR OF IS|NETWORK MGRPump Deli Clerk|PUMP MGR
4Grouping2Pump Deli Clerk|PUMP MGR|PUMP DIRECTOR
5Grouping2PUMP MGR|PUMP FOOD COURT AST MGR|PUMP FOOD COURT ASSOCIATE|PUMP SALES ASSOCIATE|PUMP MAINTENANCE CLERK|STORE ASSOC UNDER 19|PUMP 1ST ASST MGR|Pump Deli Clerk
Sheet3
Cell Formulas
RangeFormula
C3:D3C3=LET(t,TEXTSPLIT(TEXTJOIN("|",,FILTER($B$3:$B$5,$A$3:$A$5=C2)),,"|"),g,GROUPBY(t,t,COUNTA,,0),TEXTJOIN("|",,FILTER(INDEX(g,,1),INDEX(g,,2)=MAX(INDEX(g,,2)))))
I have tried this both on the actual file and a dummy sheet and it only returns a #NAME? error. Office365 does not seem to want to recognize groupby().
 
Upvote 0
Hello,

I think it can be simplified but this big formula should work
Excel Formula:
=LET(tblI,A3:B5,
grped,BYROW(UNIQUE(TAKE(tblI,,1)),LAMBDA(grp,TEXTJOIN("|",TRUE,FILTER(TAKE(tblI,,-1),TAKE(tblI,,1)=grp,"")))),
sep,DROP(REDUCE("",grped,LAMBDA(acc,v,VSTACK(acc,TEXTSPLIT(v,"|")))),1),
nums,MAKEARRAY(ROWS(sep),COLUMNS(sep),LAMBDA(r,c,
IFERROR(SUM(--(IFERROR(CHOOSEROWS(sep,r),0)=INDEX(sep,r,c))),0))),
maxes,BYROW(nums,MAX),
vals,MAKEARRAY(ROWS(sep),COLUMNS(sep),LAMBDA(r,c,IF(INDEX(nums,r,c)=CHOOSEROWS(maxes,r),INDEX(sep,r,c),""))),
res,BYROW(vals,LAMBDA(r,TEXTJOIN("|",TRUE,UNIQUE(r,TRUE)))),
TRANSPOSE(HSTACK(UNIQUE(A3:A5),res)))
 
Upvote 0
Hello,

I think it can be simplified but this big formula should work
Excel Formula:
=LET(tblI,A3:B5,
grped,BYROW(UNIQUE(TAKE(tblI,,1)),LAMBDA(grp,TEXTJOIN("|",TRUE,FILTER(TAKE(tblI,,-1),TAKE(tblI,,1)=grp,"")))),
sep,DROP(REDUCE("",grped,LAMBDA(acc,v,VSTACK(acc,TEXTSPLIT(v,"|")))),1),
nums,MAKEARRAY(ROWS(sep),COLUMNS(sep),LAMBDA(r,c,
IFERROR(SUM(--(IFERROR(CHOOSEROWS(sep,r),0)=INDEX(sep,r,c))),0))),
maxes,BYROW(nums,MAX),
vals,MAKEARRAY(ROWS(sep),COLUMNS(sep),LAMBDA(r,c,IF(INDEX(nums,r,c)=CHOOSEROWS(maxes,r),INDEX(sep,r,c),""))),
res,BYROW(vals,LAMBDA(r,TEXTJOIN("|",TRUE,UNIQUE(r,TRUE)))),
TRANSPOSE(HSTACK(UNIQUE(A3:A5),res)))
That IS a big formula! Unfortunately, like Cubist's response, I receive a #NAME? error.
 
Upvote 0
I have tried this both on the actual file and a dummy sheet and it only returns a #NAME? error. Office365 does not seem to want to recognize groupby().
You probably don't have the latest. Alternative:
Book1
ABCD
1DataDesired Result
2idoutputGrouping1Grouping2
3Grouping1CIO|DIRECTOR OF IS|NETWORK MGRCIO|DIRECTOR OF IS|NETWORK MGRPump Deli Clerk|PUMP MGR
4Grouping2Pump Deli Clerk|PUMP MGR|PUMP DIRECTOR
5Grouping2PUMP MGR|PUMP FOOD COURT AST MGR|PUMP FOOD COURT ASSOCIATE|PUMP SALES ASSOCIATE|PUMP MAINTENANCE CLERK|STORE ASSOC UNDER 19|PUMP 1ST ASST MGR|Pump Deli Clerk
Sheet3
Cell Formulas
RangeFormula
C3:D3C3=LET(t,TEXTSPLIT(TEXTJOIN("|",,FILTER($B$3:$B$5,$A$3:$A$5=C2)),,"|"),ct,MAP(t,LAMBDA(m,SUM(--(m=t)))),TEXTJOIN("|",,UNIQUE(FILTER(t,ct=MAX(ct)))))
 
Upvote 1
Solution
You probably don't have the latest. Alternative:
Book1
ABCD
1DataDesired Result
2idoutputGrouping1Grouping2
3Grouping1CIO|DIRECTOR OF IS|NETWORK MGRCIO|DIRECTOR OF IS|NETWORK MGRPump Deli Clerk|PUMP MGR
4Grouping2Pump Deli Clerk|PUMP MGR|PUMP DIRECTOR
5Grouping2PUMP MGR|PUMP FOOD COURT AST MGR|PUMP FOOD COURT ASSOCIATE|PUMP SALES ASSOCIATE|PUMP MAINTENANCE CLERK|STORE ASSOC UNDER 19|PUMP 1ST ASST MGR|Pump Deli Clerk
Sheet3
Cell Formulas
RangeFormula
C3:D3C3=LET(t,TEXTSPLIT(TEXTJOIN("|",,FILTER($B$3:$B$5,$A$3:$A$5=C2)),,"|"),ct,MAP(t,LAMBDA(m,SUM(--(m=t)))),TEXTJOIN("|",,UNIQUE(FILTER(t,ct=MAX(ct)))))
That does it! Thank you!
Are you trying this in 365 or 2019?
365
 
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