Return the most frequent text result in column J, only if the workplan category (column I), matches the column A.

kennysmith1

New Member
Joined
May 24, 2024
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
ex. "Business Office" (A2), the result in B2 would display "Omitted charges" as it is the most frequent text in column J for that workplan category. (Omitted charges 4x), (Data entry error 2x).
I have been trying to use index/match/mode functions with no success, as well as getpivot data functions.
 

Attachments

  • Capture.PNG
    Capture.PNG
    75.6 KB · Views: 22

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome to the MrExcel forum!

Try:

Book1
ABCDEFGHIJ
1Workplan categoryResultAnalystJonWorkplan CategoryRootCause
2Business OfficeOmitted ChargesBusiness OfficeData Entry Error
3Capsule Endoscopy#N/ABusiness OfficeOmitted Charges
4Declot Access DeviceOmitted ChargesBusiness OfficeOmitted Charges
5ED POCT UltrasoundModifier Missing or InvalidBusiness OfficeOmitted Charges
6Epic WQ - Marker#N/ABusiness OfficeData Entry Error
7Epic WQ - CAS Multiple Units#N/ABusiness OfficeOmitted Charges
8Capsule EndoscopyOmitted Charges
9Declot Access DeviceData Entry Error
10Declot Access DeviceData Entry Error
11Declot Access DeviceAdministration Type Change
12Declot Access DeviceOmitted Charges
13Declot Access DeviceAdministration Type Change
14Declot Access DeviceOmitted Charges
15Declot Access DeviceOmitted Charges
16ED POCT UltrasoundOmitted Charges
17ED POCT UltrasoundOmitted Charges
18ED POCT UltrasoundOmitted Charges
19ED POCT UltrasoundOmitted Charges
20ED POCT UltrasoundOmitted Charges
21ED POCT UltrasoundOmitted Charges
22ED POCT UltrasoundOmitted Charges
23ED POCT UltrasoundModifier Missing or Invalid
24ED POCT UltrasoundModifier Missing or Invalid
25ED POCT UltrasoundModifier Missing or Invalid
26ED POCT UltrasoundModifier Missing or Invalid
27ED POCT UltrasoundModifier Missing or Invalid
28ED POCT UltrasoundModifier Missing or Invalid
29ED POCT UltrasoundModifier Missing or Invalid
30ED POCT UltrasoundModifier Missing or Invalid
31ED POCT UltrasoundModifier Missing or Invalid
32ED POCT UltrasoundModifier Missing or Invalid
Sheet7
Cell Formulas
RangeFormula
B2:B7B2=INDEX($J$2:$J$32,MODE(IF($I$2:$I$32=A2,MATCH($J$2:$J$32,$J$2:$J$32,0))))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 1
thanks Eric this is awesome!!! is it possible for the formula to work for the entire column J?
Ex. there are more results past row 32 and each month the file will change (~10,000 rows, etc) so wondering if there is a formula that will capture the entire column. i tried this and unfortunately if i update that J2:J32 to J:J this will read all the blank values in the column for the mode.
 
Upvote 0
i also noticed that i may have to include an IFERROR portion for those results where the MODE formula returns an error as there is only one result?
 
Upvote 0
In theory, you could use whole column references, but I wouldn't recommend it. Even with 10,000 rows, that's less than 1% of a column, and checking the entire column would slow down the calculations to a noticeable extent. I'd recommend creating a formula to find the last row, then using that in the main formula. Like this:

Book1
ABCDEFGHIJKL
1Workplan categoryResultAnalystJonWorkplan CategoryRootCauseLastRow
2Business OfficeOmitted ChargesBusiness OfficeData Entry Error32
3Capsule EndoscopyOmitted ChargesBusiness OfficeOmitted Charges
4Declot Access DeviceData Entry ErrorBusiness OfficeOmitted Charges
5ED POCT UltrasoundAdministration Type ChangeBusiness OfficeOmitted Charges
6Epic WQ - Marker#N/ABusiness OfficeData Entry Error
7Epic WQ - CAS Multiple Units#N/ABusiness OfficeOmitted Charges
8Capsule EndoscopyOmitted Charges
9Declot Access DeviceData Entry Error
10Declot Access DeviceData Entry Error
11Declot Access DeviceAdministration Type Change
12Declot Access DeviceOmitted Charges
13Declot Access DeviceAdministration Type Change
14Declot Access DeviceOmitted Charges
15Declot Access DeviceOmitted Charges
16ED POCT UltrasoundOmitted Charges
17ED POCT UltrasoundOmitted Charges
18ED POCT UltrasoundOmitted Charges
19ED POCT UltrasoundOmitted Charges
20ED POCT UltrasoundOmitted Charges
21ED POCT UltrasoundOmitted Charges
22ED POCT UltrasoundOmitted Charges
23ED POCT UltrasoundModifier Missing or Invalid
24ED POCT UltrasoundModifier Missing or Invalid
25ED POCT UltrasoundModifier Missing or Invalid
26ED POCT UltrasoundModifier Missing or Invalid
27ED POCT UltrasoundModifier Missing or Invalid
28ED POCT UltrasoundModifier Missing or Invalid
29ED POCT UltrasoundModifier Missing or Invalid
30ED POCT UltrasoundModifier Missing or Invalid
31ED POCT UltrasoundModifier Missing or Invalid
32ED POCT UltrasoundModifier Missing or Invalid
Sheet7
Cell Formulas
RangeFormula
L2L2=LOOKUP(2,1/(J:J<>""),ROW(J:J))
B2:B7B2=IFERROR(INDEX($J$2:INDEX($J:$J,LastRow),MODE(IF($I$2:INDEX($I:$I,LastRow)=A2,MATCH($J$2:INDEX($J:$J,LastRow),$J$2:INDEX($J:$J,LastRow,0))))),VLOOKUP(A2,$I$2:INDEX($J:$J,LastRow),2,0))
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
LastRow=Sheet7!$L$2B2:B7


I used a Named Range, but there are other ways to do this. I added the IFERROR in case of a single matching row, but you'll still get the #N/A error for no matches.
 
Upvote 0
thank you very much Eric, i think this is getting very close to what I am looking for. Im trying the formula without the IFERROR function, and am now getting an error for some even though there is clearly a MODE. Ex. 'LI OBOP Sample - IV Therapy' should return "IV Start/Stop time missing", but instead returns an error #N/A.
'LI OBOP Sample - Laboratory' correctly returns "omitted charges", not sure why this is? Note i transposed the formula to use the same columns in different locations, and also created a separate key to vlookup.

=INDEX('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),MODE(IF('Raw Data'!$AN$2:INDEX('Raw Data'!$AN:$AN,Key!$D$4)=Sheet32!C22,MATCH('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),'Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4,0)))))
 

Attachments

  • excel.PNG
    excel.PNG
    22 KB · Views: 5
  • IV Therapy.PNG
    IV Therapy.PNG
    50.7 KB · Views: 16
  • laboratory.PNG
    laboratory.PNG
    34.1 KB · Views: 25
Upvote 0
Looking at your data, I don't see anything that would cause your issue. My best guess would be that the keys don't match. A trailing space that you can't see, or some undisplayable character. In order to troubleshoot this, are you able to use the xl2bb add-in? This will allow you to copy your exact data (like I did in posts 2 and 5) so that I can copy it directly to my Excel and work with it. When I look at a picture like you've shown, it's easy to miss something. Look at the link in my signature, or in the reply box. It's easy to download, install, and use.
 
Upvote 0
Cell Formulas
RangeFormula
C22:C27C22=CONCATENATE(A22," - ",B22)
D22:D27D22=SUMIFS('Raw Data'!AD:AD,'Raw Data'!AJ:AJ,Sheet32!A22,'Raw Data'!Y:Y,Sheet32!B22)
E22:E27E22=COUNTIFS('Raw Data'!AJ:AJ,Sheet32!A22,'Raw Data'!Y:Y,Sheet32!B22)
F22:F27F22=SUMIFS('Raw Data'!AG:AG,'Raw Data'!AJ:AJ,Sheet32!A22,'Raw Data'!Y:Y,Sheet32!B22,'Raw Data'!AB:AB,"Undercharge")
G22:G27G22=SUMIFS('Raw Data'!AG:AG,'Raw Data'!AJ:AJ,Sheet32!A22,'Raw Data'!Y:Y,Sheet32!B22,'Raw Data'!AB:AB,"Overcharge")
H22:H27H22=IFERROR(INDEX('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),MODE(IF('Raw Data'!$AN$2:INDEX('Raw Data'!$AN:$AN,Key!$D$4)=Sheet32!C22,MATCH('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),'Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4,0))))),VLOOKUP(Sheet32!C22,'Raw Data'!$AN$2:INDEX('Raw Data'!$AP:$AP,Key!$D$4),3,0))
I22:I27I22=INDEX('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),MODE(IF('Raw Data'!$AN$2:INDEX('Raw Data'!$AN:$AN,Key!$D$4)=Sheet32!C22,MATCH('Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4),'Raw Data'!$AE$2:INDEX('Raw Data'!$AE:$AE,Key!$D$4,0)))))
J22:J27J22=VLOOKUP(Sheet32!C22,'Raw Data'!$AN$2:INDEX('Raw Data'!$AP:$AP,Key!$D$4),3,0)
Press CTRL+SHIFT+ENTER to enter array formulas.
Named Ranges
NameRefers ToCells
RootCause='Raw Data'!$AE$2:$AE$1048576H22:I27
 
Upvote 0
Thanks was able to install let me know if the formatting is ok or if any data is missing, first time using x2lbb
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,123
Members
453,021
Latest member
Justyna P

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