Finding MAX of a text string based on numerically assigned values in a separate table.

vlamish

New Member
Joined
Jun 6, 2016
Messages
2
Having used the MrExcel forums for plenty of excel help over the past months, I have finally found something that google searches don't seem to provide answers for. So, here goes.

I have a set of data that is based off of a business number. Multiple instances of the same business number can appear in the table if the business has multiple locations. I am trying to calculate hours of operation outside of a specific window based on the hours given and the frequency of those hours (once a month, bi-weekly, weekly, etc). I have a separate table for these calculations and I've already used MAXIF and MINIF to find the best open/close hours. I had used a complicated set of if, index, and vlookup functions to find appropriate data based on whether an office becomes closed. However, the limit of this complicated mess has been reached.

I already have assigned numeric values to the 5 options in my frequency columns: "" = 0, "Closed" = 0, "monthly" = 1, "bi-weekly" = 2, "weekly" = 4. What I want to do is have a max function that looks up all instances of a business number, finds the maximum value of the frequency (based on the lookup table I created) and then prints the specific text into my calculation table.

example:
office #addressmon openmon closemon freq
12123 fake9:00 AM8:00 PMmonthly
12456 fake7:00 AM5:00 PMbi-weekly
12789 fakeClosedClosedClosed
12still fake9:00 AM6:00 PMweekly

<tbody>
</tbody>

0
Closed0
monthly1
bi-weekly2
weekly4

<tbody>
</tbody>
Note: the blank cell is indeed blank, or "".


I can correctly get 7:00 AM as the earliest open, I can correctly find 8:00 PM as the latest close. I cannot correctly select "weekly" as the MAX text option based on its assigned value of 4. I know this will need to be an array formula, but I simply cannot construct a formula based on the logic in my head. Any help would be greatly appreciated.

p.s. Yes, I realize that the 7:00 AM open time should theoretically be paired with a bi-weekly value of 2, but that simply isn't how we calculate things. We take earliest open, earliest close, and best frequency to calculate hours.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Not sure I follow your logic?: Is this what your looking to do?

I have a set of data that is based off of a business number. Multiple instances of the same business number can appear in the table if the business has multiple locations. I am trying to calculate hours of operation outside of a specific window based on the hours given and the frequency of those hours (once a month, bi-weekly, weekly, etc).


Excel 2010
ABCDEFGH
1office #addressmon openmon closemon freqMax Weekly Open11:00 AM
212123 fake9:00 AM8:00 PMmonthlyMax Weekly Close11:30 PM
312456 fake7:00 AM5:00 PMbi-weeklyMin Weekly Open2:00 AM
412789 fakeClosedClosedClosedMin Weekly Close3:00 PM
512still fake9:00 AM3:00 PMweekly
612456 fake7:00 AM8:00 PMbi-weekly
712789 fakeClosedClosedClosed
812still fake11:00 AM11:00 PMweekly
912123 fake9:00 AM8:00 PMmonthly
1012456 fake7:00 AM5:00 PMbi-weekly
1112789 fakeClosedClosedClosed
1212still fake9:00 AM11:30 PMweekly
1312456 fake7:00 AM8:00 PMbi-weekly
1412789 fakeClosedClosedClosed
1512still fake2:00 AM4:00 PMweekly
Sheet1
Cell Formulas
RangeFormula
H1=IFERROR(AGGREGATE(14,6,$C$2:$C$15/--($E$2:$E$15="weekly"),1),"")
H2=IFERROR(AGGREGATE(14,6,$D$2:$D$15/--($E$2:$E$15="weekly"),1),"")
H3=IFERROR(AGGREGATE(15,6,$C$2:$C$15/--($E$2:$E$15="weekly"),1),"")
H4=IFERROR(AGGREGATE(15,6,$D$2:$D$15/--($E$2:$E$15="weekly"),1),"")
 
Upvote 0
Instead of trying to fail with more English, I created a few examples:

Imgur: The most awesome images on the Internet

The first screenshot is of my data table where I'm pulling all of the data. Sensitive information has been scrubbed and replaced by silliness.

The second screenshot contains my trouble. At the bottom of the screenshot, I provided the formulas I'm using (a minif and a maxif) to get the hours into this new calculations table above it. I have example data. As you can see, both the second and third examples have a close time of .833 hours (corresponds to 8pm). Thus my calculation in column E to calculate total hours reduces down to (8pm-6pm = 2 hour time difference ; 2 hours * weekly [4] = 8 qualifying hours).

My issue is this:
if data from group 1 in screenshot one has: their first location has monthly hours (a value of 1 within my j:k table), and their second location has weekly hours (a value of 4 in my j:k table), I want to choose weekly. I want "weekly" to show up in column D from the second screenshot so that my column E can be calculated correctly.

So, going back to screenshot 1:
I need to look up the group #, potentially with multiple instances within my table, and choose the maximum value in the "day freq" columns. I need a formula that will look at all entries in the column for any group # and choose the largest of them all.

I cannot modify the table from the first screenshot, as it is directly presented to others. The second screenshot, however, is just for me and I can do whatever to it.
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,464
Members
449,163
Latest member
kshealy

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