Return true/false for each row for the maximum of a subset data in an array

dlortie

New Member
Joined
Jan 30, 2016
Messages
6
Hi,

I have the following data where I need to return whether I am on the maximum row based on multiple criteria
I will have the formula in the formula column for each row in the example below with a TRUE or FALSE.
In the example below, I should see TRUE in Rows 2 and 15.

Basically for each unique identifier, I need to find the most recent start date and then for these most recent start dates, I need to find the row with the largest step.

I understand array formulas, but I cannot seem to get this to work - specifically for a subset of data.

RowId Identifier Start Date Step Formula
1 73643769 FALSE
2 73643769 2015-12-09 5 TRUE
3 73643769 2015-12-09 0 FALSE
4 73643769 2015-10-06 5 FALSE
5 73643769 2015-10-06 0 FALSE
6 73643769 2015-02-07 8 FALSE
7 73643769 2015-02-07 8 FALSE
8 73643769 2015-02-07 0 FALSE
9 73643769 2015-02-07 0 FALSE
10 73643769 8 FALSE
11 73643769 8 FALSE
12 73643769 8 FALSE
13 73643769 8 FALSE
14 12345678 2015-02-04 5 FALSE
15 12345678 2015-02-04 8 TRUE
16 12345678 2015-02-02 0 FALSE
17 12345678 8 FALSE
18 12345678 8 FALSE
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
See if this might work for you.
Copy down as needed.
Excel Workbook
ABCDE
1RowIdIdentifierStart DateStepFormula
2173643769FALSE
327364376912/9/20155TRUE
437364376912/9/20150FALSE
547364376910/6/20155FALSE
657364376910/6/20150FALSE
76736437692/7/20158FALSE
87736437692/7/20158FALSE
98736437692/7/20150FALSE
109736437692/7/20150FALSE
1110736437698FALSE
1211736437698FALSE
1312736437698FALSE
1413736437698FALSE
1514123456782/4/20155FALSE
1615123456782/4/20158TRUE
1716123456782/2/20150FALSE
1817123456788FALSE
1918123456788FALSE
Sheet
 
Upvote 0
@AhoyNC

We can avoid two IF calls with an AND call...

{=AND(C2=MAX(IF($B$2:$B$19=B2,$C$2:$C$19)),D2=MAX(IF($C$2:$C$19=MAX(IF($B$2:$B$19=B2,$C$2:$C$19)),$D$2:$D$19)))}

If the range is huge, it might be wise to use the V() function to avoid computing the same expensive expression twice...

{=AND(C2=V(MAX(IF($B$2:$B$19=B2,$C$2:$C$19))),D2=MAX(IF($C$2:$C$19=V(),$D$2:$D$19)))}

For the latter to work, we need to install the V() function using Alt+F11 of which the code is as follows:

Public Function V(Optional vrnt As Variant) As Variant
'
' Stephen Dunn
' 2002-09-12
'
Static vrntV As Variant
If Not IsMissing(vrnt) Then vrntV = vrnt
V = vrntV
End Function
 
Upvote 0
Hi,

Thanks for the replies.

I tried the 1st answer which works very well except that I need to keep only one row for each unique identifier - the above will match many rows if they have the same max date and max step.

I tried the second answer with the UDF, but I can seem to get excel to recognize it....I get #NAME - I see ther UDF in the formula dialog box, but it seems to require the full worksheet name...I do have over 20k rows.

Thanks,
Daniel Lortie
 
Upvote 0
Hi,

Thanks for the replies.

I tried the 1st answer which works very well except that I need to keep only one row for each unique identifier - the above will match many rows if they have the same max date and max step.

I tried the second answer with the UDF, but I can seem to get excel to recognize it....I get #NAME - I see ther UDF in the formula dialog box, but it seems to require the full worksheet name...I do have over 20k rows.

Thanks,
Daniel Lortie

Try to post a sample that illustrates the issue you seem to have. (By the way, the formulas are equivalent. That with V() requires adding V() to your workbook.)
 
Upvote 0
Here is an additional restriction which will allow me to return only one row per individual resource. I added the rate column where on top of the existing conditions, I need to only select the maximum salary for each unique Personnel number with maximum start date and maximum step (for the subset of maximum start date)

RowIdPersonnel NumberStart DateStepPay RateFormulaFormula Result (AND)Formula Result (AND)+V()Desired Result
11234567816-Jan-16495222TRUETRUEFALSE
21234567816-Jan-164112359TRUETRUETRUE
31234567831-Dec-158105000FALSEFALSEFALSE
41234567831-Dec-15595000FALSEFALSEFALSE
512345678FALSEFALSEFALSE
612345678FALSEFALSEFALSE
712345678FALSEFALSEFALSE
84567890124-Dec-165107000FALSEFALSEFALSE
94567890124-Dec-168125000TRUETRUETRUE
104567890124-Dec-168102000TRUETRUEFALSE
114567890101-Jun-15388000FALSEFALSEFALSE
124567890101-Jun-15875000FALSEFALSEFALSE
1345678901FALSEFALSEFALSE
1445678901FALSEFALSEFALSE

<tbody>
</tbody><colgroup><col><col><col><col><col><col><col><col><col><col></colgroup>
<strike></strike>

Regards,
Daniel Lortie
 
Upvote 0
No need to include the formula results in your exhibit... Note that none of the formulas wrong given the conditions you have stipulated at the outset. With the additional condition that you throw in...

Row\Col
A​
B​
C​
D​
E​
F​
1​
RowId Personnel Number Start Date Step Pay Rate Formula
2​
1
12345678
16-Jan-16
4
95222
FALSE
3​
2
12345678
16-Jan-16
4
112359
TRUE
4​
3
12345678
31-Dec-15
8
105000
FALSE
5​
4
12345678
31-Dec-15
5
95000
FALSE
6​
5
12345678
FALSE
7​
6
12345678
FALSE
8​
7
12345678
FALSE
9​
8
45678901
24-Dec-16
5
107000
FALSE
10​
9
45678901
24-Dec-16
8
125000
TRUE
11​
10
45678901
24-Dec-16
8
102000
FALSE
12​
11
45678901
1-Jun-15
3
88000
FALSE
13​
12
45678901
1-Jun-15
8
75000
FALSE
14​
13
45678901
FALSE
15​
14
45678901
FALSE

In F2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=AND(
    C2=MAX(IF($B$2:$B$15=B2,$C$2:$C$15)),
    D2=MAX(IF($C$2:$C$15=MAX(IF($B$2:$B$15=B2,$C$2:$C$15)),$D$2:$D$15)),
    E2=MAX(IF($D$2:$D$15=MAX(IF($C$2:$C$15=MAX(IF($B$2:$B$15=B2,$C$2:$C$15)),
      $D$2:$D$15)),$E$2:$E$15)))

With V(), we get:
Rich (BB code):
<strike></strike>=AND(
    C2=V(MAX(IF($B$2:$B$15=B2,$C$2:$C$15))),
    D2=MAX(IF($C$2:$C$15=V(),$D$2:$D$15)),
    E2=MAX(IF($D$2:$D$15=MAX(IF($C$2:$C$15=V(),$D$2:$D$15)),$E$2:$E$15)))<strike></strike>
 
Upvote 0
Hi,

I have to figure out why the function worked in my Excel 2016 at home and returns #NAME in my Excel 2010 at work. I can confirm that the V() function is in the workbook code and I can see it in the formula dialogue.

...Yes I added a salary column to get unique rows...I understand that every answer provided meets my initial requirements as well as the additional requirement for unique rows.

Thanks for all of your help!

Daniel
 
Upvote 0
Hi,

I have to figure out why the function worked in my Excel 2016 at home and returns #NAME in my Excel 2010 at work. I can confirm that the V() function is in the workbook code and I can see it in the formula dialogue.

Should work in Excel 2000 too. Make sure that it's added as a module.

...Yes I added a salary column to get unique rows...I understand that every answer provided meets my initial requirements as well as the additional requirement for unique rows.

Thanks for all of your help!

Daniel

You are welcome.
 
Upvote 0
I have an issue with the last answer that was provided that took into account the pay rate column for uniqueness.

On Row 2, I am expecting this to return TRUE as it represents for Personnel number 73643769 the last pay action (max date: 09-Dec-15) as well as the max step for that max date (step 5 for date 09-Dec-15 for Personnel 73643769). When I step through/evaluate the formula, it seems to ignore the Personnel restriction and returns the max salary of 118,666.00 (for a different Personnel Number)

For example in E3 => Stepping through the formula the last part of the formula does not seem to restrict on the Personnel number or the largest date and tries to match the largest pay for a step of 5

E3 Partial eval
AND(TRUE, TRUE, 102059=MAX(IF({-1;5;0;5;0;8;8;0;0;8;5;-1;8;0;5;0;8}=5,E$2:E$18)))

AND(TRUE, TRUE, 102059=MAX(IF({FALSE;TRUE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE},E$2:E$18)))

AND(TRUE, TRUE, 102059=118666)

AND(TRUE, TRUE, FALSE)

RowId Personnel number Start Date Step Pay Rate Formula Comment
1 73643769 -1 FALSE
2 73643769 09-Dec-15 5 102,059.00 FALSE Expecting True
3 73643769 09-Dec-15 0 0 FALSE
4 73643769 06-Oct-15 5 102,059.00 FALSE
5 73643769 2015-10-06 0 0 FALSE
6 73643769 2015-02-07 8 97,322.00 FALSE
7 73643769 2015-02-07 8 97,322.00 FALSE
8 73643769 07-Feb-15 0 0 FALSE
9 73643769 07-Feb-15 0 0 FALSE
10 73643769 8 0 FALSE
11 73643769 5 0 FALSE
12 32837275 -1 FALSE
13 32837275 2015-04-25 8 111,639.00 TRUE
14 32837275 2015-04-25 0 0 FALSE
15 32837275 2014-06-02 5 118,666.00 FALSE
16 32837275 2014-06-02 0 0 FALSE
17 32837275 8 0 FALSE
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,831
Members
449,471
Latest member
lachbee

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