Returning adjacent text cell for the maximum occurrence within groups of IDs

JayHero

New Member
Joined
Jan 21, 2016
Messages
5
Help with returning adjacent text cell for the maximum occurrence within groups of IDs
Data:
[TABLE="width: 605"]
<tbody>[TR]
[TD]ID (A)
[/TD]
[TD]CODE (B)
[/TD]
[TD]SKU Count (C)
[/TD]
[TD]Code Occurrence (D)
[/TD]
[TD]Code % Of Occurrence
(E)
[/TD]
[TD]Max Occurrence % (H)
[/TD]
[TD]Results Needed
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]A
[/TD]
[TD]6
[/TD]
[TD]4
[/TD]
[TD]0.67
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]B
[/TD]
[TD]6
[/TD]
[TD]2
[/TD]
[TD]0.33
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]A
[/TD]
[TD]6
[/TD]
[TD]4
[/TD]
[TD]0.67
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]A
[/TD]
[TD]6
[/TD]
[TD]4
[/TD]
[TD]0.67
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]A
[/TD]
[TD]6
[/TD]
[TD]4
[/TD]
[TD]0.67
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]B
[/TD]
[TD]6
[/TD]
[TD]2
[/TD]
[TD]0.33
[/TD]
[TD]0.67
[/TD]
[TD]A
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]A
[/TD]
[TD]5
[/TD]
[TD]1
[/TD]
[TD]0.20
[/TD]
[TD]0.40
[/TD]
[TD]B
[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1 but not for SKU 2 & 3
=INDEX($A$2:$H$18,MATCH(A2,$A$2:$A$18,0)*MATCH(H2,$E$2:$E$18,0),2)
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

@JayHero, see if this works for you (assuming your headers are in Row 1 and your data starts in Row 2):

=INDEX(B$2:B$18,SUMPRODUCT(MAX((A$2:A$18=A2)*(E$2:E$18=H2)*(ROW(A$2:A$18)-1))))

I used SUMPRODUCT() to avoid needing to enter as an array formula.
 
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

@JayHero

Could you confirm/explain what the expected result(s) would be for this sample data?


Book1
AB
1ID (A)CODE (B)
21A
31B
41C
51B
61C
71D
81A
9
Example
 
Last edited:
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

Thanks Erik it work perfectly. I did try variations using "sumproduct' and "row" but could not get those to work quite right too.
 
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

Peter, Erik's solution above worked for me. However, if you have a solution that returns the text that occurs the most frequent per Id without using the extra percent column i was using to do this, that would be great too.

[TABLE="width: 202"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]ID CODE Results
1 A A
1 B A
1 A A
1 A A
1 A A
1 B A
2 A B
2 B B
2 B B
2 C B
2 D B
3 A C
3 B C
3 C C
3 C C
3 E C
3 D C
4 B B
4 A B
4 B B
4 B B
4 A B
4 B B


[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

@JayHero, if you want to avoid using helper Column H, you can use the following array formula:

Code:
=INDEX(B$2:B$18,MAX((A$2:A$18=A2)*(E$2:E$18=MAX(IF(A$2:A$18=A2,E$2:E$18)))*(ROW(A$2:A$18)-1)))

Just be sure to use Ctrl+Shift+Enter.
 
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

Peter, Erik's solution above worked for me. However, if you have a solution that returns the text that occurs the most frequent per Id without using the extra percent column i was using to do this, that would be great too.
I think you missed the point of my question, or else I have misunderstood your question. :)
In my example, there are three codes that all have equal maximum occurrence within ID 1.
I was just questioning why, of if, you only want one of them returned in the 'Results Needed' column?
 
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

Peter I am follow you now after rereading your first post. I did consider this initially and did a quick scan of my data and found 1 or 2 such instances. I will do a more thorough check but the chances of this occurring due to the nature of the items in my data is low and i am willing to accept a few areas where I will need to dig down into it more. The data I pulled for this is not large only about 8000 rows. There will be no more than 12 repeated Id occurrences and there are only about 10 codes total. Also, there should be no more the 4-5 unique codes per Id with the majority being 2-3 unique codes per Id. I built-in additional COUNTIF, COUNTIFS, SUMIF and percent occurrences columns to help me filter down to take a closer look. I appreciate your insight on this and any additional suggestions will also be appreciated.
 
Last edited:
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

.. any additional suggestions will also be appreciated.
See if this is any use. It uses just columns A, B and D but does require Excel 16 through Office 365.
D2 is copied down
I2 is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

Excel Workbook
ABDI
1ID (A)CODE (B)Code Occurrence (D)Codes with Max Occur.
21A2A, C, D
31B1A, C, D
41C2A, C, D
51D2A, C, D
61C2A, C, D
71D2A, C, D
81A2A, C, D
92A1B
102B2B
112B2B
122C1B
132D1B
143A1C
153B1C
163C2C
173C2C
183E1C
193D1C
Example
 
Upvote 0
Re: Help with returning adjacent text cell for the maximum occurrence within groups of IDs

If you don't have the appropriate Excel version with TEXTJOIN and MAXIFS, then perhaps this array formula, still only using columns A, B & D may be of use.

Excel Workbook
ABDI
1ID (A)CODE (B)Code Occurrence (D)Codes with Max Occur.
21A3Multiple
31B1Multiple
41C3Multiple
51C3Multiple
61C3Multiple
71A3Multiple
81A3Multiple
92A1B
102B2B
112B2B
122C1B
132D1B
143A1C
153B1C
163C2C
173C2C
183E1C
193D1C
Example (2)





:warning: A word of warning: If you do continue to use Erik's formula, be aware that if you, or another user, subsequently inserts any new rows at the top of the sheet, the formulas will return incorrect results.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,301
Members
452,633
Latest member
DougMo

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