Formula to determine max number in multiple dynamic arrays

jberylec

New Member
Joined
Jan 14, 2023
Messages
23
Office Version
  1. 2019
Platform
  1. Windows
This one is proving tough for me! Hope the experts can help :)

I need to create a formula in F2 that can be copied down through hundreds of location/batch rows, on a new version of this spreadsheet each day. The formula needs to find the max number in D but only for each location/batch section and report only that one into F on the same row. I've manually typed them in F just for display purposes.

A and B rows are always merged for that entire location and batch, as shown. So I was trying to build a formula that would recognize each time a row in B isn't blank <>"" which indicates a new location/batch starts here, then include that row and all blank rows below it (they're merged so treated as blank cells) to find the MAX number in D and show that in F. Then of course it starts over IF B isnt blank again.

In case of a tie, show both.

FYI, there are a lot more columns of data, not relevant for this though because none can be used as an identifier, I also have many other formula columns that I paste into row 2 each morning, then drag them all down the entire sheet, so trying to keep this just a formula not VBA. Hoping to add this new column to my daily paste and drag routine. Ah. Exhausting just describing this. Ha! Thanks in advance
 

Attachments

  • excel.png
    excel.png
    20.7 KB · Views: 20

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)
Welcome to the MrExcel board!

For the future, it would help if you can provide your sample data and expected results in a form that helpers can copy to test with. Have a look at XL2BB
Give this a try. Where I have used 1000 near the end of the formula, make that a number that will easily exceed the number of rows of data you ever likely expect.

23 01 15.xlsm
ADE
1LocationMax
2186 
38787
484 
582 
6277 
771 
873 
978 
1074 
118181
12397 
130 
149898
1590 
1695 
17462 
1864 
1961 
2066 
217070
2269 
2367 
247070
Max per group
Cell Formulas
RangeFormula
E2:E24E2=IF(D2=MAX(INDEX(D:D,MATCH(COUNT(A$2:A2),A:A,0)):INDEX(D:D,IFNA(MATCH(COUNT(A$2:A2)+1,A:A,0)-1,1000))),D2,"")
 
Upvote 0
Another option, keeping the formulas a bit simpler but using a helper column (which could be hidden)

23 01 15.xlsm
ADEF
1LocationMax
2186 1
387871
484 1
582 1
6277 2
771 2
873 2
978 2
1074 2
1181812
12397 3
130 3
1498983
1590 3
1695 3
17462 4
1864 4
1961 4
2066 4
2170704
2269 4
2367 4
2470704
Max per group (2)
Cell Formulas
RangeFormula
E2:E24E2=IF(D2=MAXIFS(D$2:D$1000,F$2:F$1000,F2),D2,"")
F2:F24F2=IF(A2="",F1,A2)
 
Upvote 0
Hi Peter! I think I've got the XL2BB working, going to try it below to show you the results. Thank you! FYI, the first formula you posted seems to stop working at line 60, not showing a result for that group, then any further groups down it returns the n/a "Value not available" error. Weird. I cant find anything in the formula that would trip that up, nor anything in the data. Hmm. However, your second post doesn't seem to have a problem like this, You'll see that one in F and G so I'm good with this one! You're a life saver my friend. Oh, and by the way do you know how to get rid of the formula popup that blocks visibility to cells behind it when editing a formula? I use the edit bar at the top, so I dont need the popup covering my data, very annoying and I cant find anywhere to turn it off. Screen shot attached. Thanks again!

TESTING.xlsx
ABCDEFG
60987 9 
6193 9 
6291 9 
6386 9 
6489 9 
6588 9 
6698 998
6787 9 
6892 9 
6991 9 
7093 9 
7110#N/A1 
720#N/A1 
730#N/A1 
7482#N/A1 
7583#N/A1 
7686#N/A1 
7787#N/A187
7872#N/A1 
Table 1
Cell Formulas
RangeFormula
E60:E78E60=IF(D60=MAX(INDEX(D:D,MATCH(COUNT(A$2:A60),A:A,0)):INDEX(D:D,IFNA(MATCH(COUNT(A$2:A60)+1,A:A,0)-1,205))),D60,"")
F60:F78F60=IF(A60="",F59,A60)
G60:G78G60=IF(D60=MAXIFS(D$2:D$205,F$2:F$205,F60),D60,"")
 

Attachments

  • excel popup.png
    excel popup.png
    32.5 KB · Views: 9
Upvote 0
Ut oh, I spoke too soon, there are spots where option 2 doesn't return a max either. I think its maybe because the formulas are looking at the whole range of D:D for the criteria and matching based on the value of A (the location number)? But the problem with that is there will be many other groups of rows throughout the sheet with that location number further down. So if it's including those too and giving the max result to the overall max even if its way down on row 800 in a separate group? Just thinking out loud here, haven't confirmed that. But when I copy down the formulas in a live sheet with 1000s of rows and then scroll through, there are a lot of location groups without a max reported in either of these new columns. And in addition the n/a errors start in the first formula column.

In the example above we need the formula to only look at rows 60-70, and not include any other merged location groups further down that have the same location number. My thought was to have it recognize each time there's a number in A start the criteria range there and include all rows until it sees a number in A again, which ends the criteria range one row above, and of course starts a new criteria range to check for the max from that group. And so on..

I could be wrong on all that though, it's late and I've been looking at numbers all evening. Ha! Thanks again for all the help!
 
Upvote 0
Well, they do not work because your sample data for Location went 1 then 2 then 3 then 4. A fairly reasonable assumption for helpers that know nothing else about your circumstances is that that pattern would continue. ;)
Sample data that is truly representative is more likely to elicit robust responses.

See if this is better

23 01 15.xlsm
ADE
1LocationMax
2186 
38787
484 
582 
6277 
771 
873 
978 
1074 
118181
12197 
130 
149898
1590 
1695 
17262 
1864 
1961 
2066 
217070
2269 
2367 
247070
Max per group
Cell Formulas
RangeFormula
E2:E24E2=IF(D2=MAX(INDEX(D:D,AGGREGATE(14,6,ROW(A$2:A2)/(A$2:A2<>""),1)):INDEX(D:D,IFERROR(AGGREGATE(15,6,ROW(A3:A$1000)/(A3:A$100<>""),1)-1,1000))),D2,"")
 
Upvote 0
Ah ha, yes I thought of that consecutive number thing after the fact. Sorry I didn't capture enough of the sheet to show that the numbers start over and over. Anyhow this new one seems to have done the trick! Awesome. You rock! Any idea on disabling that formula popup?
 
Upvote 0
Peter, if possible, I'd like to add another column that looks at the same stuff but instead of returning the max value or blank, it returns 1, 2, or 3 (which would be the max, the second highest, and the third highest. This would be incredibly useful :) Thanks again sir! This site needs a tipping option so we can give back to you folks who help us solve these difficult problems!
 
Upvote 0
Any idea on disabling that formula popup?
I don't know what you mean.

I'd like to add another column that looks at the same stuff but instead of returning the max value or blank, it returns 1, 2, or 3 (which would be the max, the second highest, and the third highest.
I am changing back to the idea of an extra helper column as it could be used for the previous question and this new one (& possibly more).
For the new one I am not sure whether you wanted the results as shown in col G or those in col G (or something else again)?

jberylec.xlsm
ADEFGH
1LocationMaxMaxTop3Top3
21861 862
387187871
4841 843
5821   
62772 773
7712   
8732   
9782 782
10742   
1181281811
121973 972
1303   
1498398981
15903   
16953 953
174624   
18644   
19614   
20664   
2170470701
22694 693
23674   
2470470701
Max per group (3)
Cell Formulas
RangeFormula
E2:E24E2=E1+(A2<>"")
F2:F24F2=IF(D2=MAXIFS(D$2:D$1000,E$2:E$1000,E2),D2,"")
G2:G24G2=IF(D2>=AGGREGATE(14,6,D$2:D$1000/(E$2:E$1000=E2),3),D2,"")
H2:H24H2=IFNA(MATCH(COUNTIFS(E$2:E$1000,E2,D$2:D$1000,">"&D2)+1,{1,2,3},0),"")


This site needs a tipping option so we can give back to you folks who help us solve these difficult problems!
That would be a breach of #5 of the Forum Rules 😎
We do it because we want to, not for any financial reward. :)
 
Upvote 0
Solution
Ah, the formula popup I talked about in post #4 and included a screenshot. Thanks again! I'll give these latest versions a try. Awesome
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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