Formula to search max. value based on criteria in other column

roelandwatteeuw

Board Regular
Joined
Feb 20, 2015
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have this data with columns:
- A: the ID of the product
- B: the start of the proces
- C: the end of te proces
- D: the state of the proces during B to C

IDStartEndState
10028700​
1/01/2020​
31/03/2021​
Active
10028700​
1/04/2021​
31/12/9999​
Inactive
10029917​
1/07/2021​
30/09/2021​
Active
10029917​
1/10/2021​
31/12/9999​
Active
10030325​
1/10/2019​
2/03/2021​
Active
10030325​
1/04/2022​
31/12/9999​
Inactive
10031873​
1/09/2021​
3/10/2021​
Inactive
10031873​
4/10/2021​
14/11/2021​
Active
10031873​
15/11/2021​
31/01/2022​
Active
10031873
01/02/2022​
31/12/9999​
Active

What do I need:

A formula where Excel first looks at all the same ID's (A).
For those ID's I need the State (D) of the last End date (C) within all the rows with this ID.

This what it should look like:

IDStartEndStateLast state
10028700
1/01/2020​
31/03/2021​
ActiveInactive
10028700
1/04/2021​
31/12/9999
InactiveInactive
10029917
1/07/2021​
30/09/2021​
InactiveActive
10029917
1/10/2021​
31/12/9999
ActiveActive
10030325
1/04/2022​
31/12/2025
ActiveActive
10030325
1/10/2019​
31/03/2022​
InactiveActive
10031873
1/09/2021​
3/10/2021​
InactiveActive
10031873
4/10/2021​
14/11/2021​
ActiveActive
10031873
15/11/2021​
31/01/2022​
ActiveActive
10031873
01/02/2022​
31/12/9999
ActiveActive

Hope you can help me!


gr.
Roely
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
you need a formula for a max value or a formula for conditional formatting ?
Can you add those data with the XL2BB-tool ?
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDE
1IDStartEndState
21002870001/01/202031/03/2021ActiveInactive
31002870001/04/202131/12/9999InactiveInactive
41002991701/07/202130/09/2021ActiveActive
51002991701/10/202131/12/9999ActiveActive
61003032501/10/201902/03/2021ActiveInactive
71003032501/04/202231/12/9999InactiveInactive
81003187301/09/202103/10/2021InactiveActive
91003187304/10/202114/11/2021ActiveActive
101003187315/11/202131/01/2022ActiveActive
111003187301/02/202231/12/9999ActiveActive
Main
Cell Formulas
RangeFormula
E2:E11E2=INDEX(SORT(FILTER(B2:D11,A2:A11=A2),1,-1),1,3)
 
Upvote 0
you need a formula for a max value or a formula for conditional formatting ?
Can you add those data with the XL2BB-tool ?
Hi, Thx for the help.
I need a formula for the max value. (But only the max for the same ID. And for this max I need the corresponding State with this value.).
This has nothing to do with conditional formatting. ?
 
Upvote 0
How about
+Fluff 1.xlsm
ABCDE
1IDStartEndState
21002870001/01/202031/03/2021ActiveInactive
31002870001/04/202131/12/9999InactiveInactive
41002991701/07/202130/09/2021ActiveActive
51002991701/10/202131/12/9999ActiveActive
61003032501/10/201902/03/2021ActiveInactive
71003032501/04/202231/12/9999InactiveInactive
81003187301/09/202103/10/2021InactiveActive
91003187304/10/202114/11/2021ActiveActive
101003187315/11/202131/01/2022ActiveActive
111003187301/02/202231/12/9999ActiveActive
Main
Cell Formulas
RangeFormula
E2:E11E2=INDEX(SORT(FILTER(B2:D11,A2:A11=A2),1,-1),1,3)
Hi, thx for the help!


I had a similar formula with the same result, but, when I sort the values of colomn A ascending + thé value of column C from old to new, the result isn't not good anymore.

Then I got ... (red is wrong)

IDStartEndStateLast state
100287001/04/202131/12/9999InactiveInactive
100287001/01/202031/03/2021ActiveActive
100299171/10/202131/12/9999ActiveActive
100299171/07/202130/09/2021InactiveInactive
100303251/04/202231/12/2025InactiveInactive
100303251/10/201931/03/2022ActiveActive
1003187301/02/202231/12/9999ActiveActive
1003187315/11/202131/01/2022ActiveActive
1003187304/10/202114/11/2021ActiveActive
1003187301/09/202103/10/2021InactiveInactive

I need a more consistent formula...
I thought it would be simple, but trying proofed me wrong.


After a long search I think I found the good solution:
=@XLOOKUP(A2 & "-" & (MAXIFS(C:C,A:A,@A:A)),$A$1:A10 & "-" & $C$1:C10,$D$1:D10)

MAXIFS(C:C,A:A,@A:A) searchs the max.value for the corresponding ID
@XLookup searchs the combination of the ID and the maximum value and returns the State in column D
(yeah, I could use an extra column to concatenate the two colomns)

Somebody who knows what the @ is for before XLOOPUP and befor A:A? (Excel made the edit automatic)
 
Upvote 0
I forgot to lock the ranges when I posted the formula, but when that is done, it doesn't matter how the data is sorted.
+Fluff 1.xlsm
ABCDE
1IDStartEndState
21002870001/01/202031/03/2021ActiveInactive
31002870001/04/202131/12/9999InactiveInactive
41002991701/07/202130/09/2021ActiveActive
51002991701/10/202131/12/9999ActiveActive
61003032501/10/201902/03/2021ActiveInactive
71003032501/04/202231/12/9999InactiveInactive
81003187301/09/202103/10/2021InactiveActive
91003187304/10/202114/11/2021ActiveActive
101003187315/11/202131/01/2022ActiveActive
111003187301/02/202231/12/9999ActiveActive
Main
Cell Formulas
RangeFormula
E2:E11E2=INDEX(SORT(FILTER($B$2:$D$11,$A$2:$A$11=A2),1,-1),1,3)
 
Upvote 0
Solution
Hi Fluff

Works great as well. Thanks!
I don't know which one is better.
It works and that's the most important ;)
But I think I will use yours :)


Additional question (or should I make a new post?):
Do you know how to make the range more flexible.
I mean, now you've got '$B$2:$D$11' and '$A$2:$A$11'
but row 11 isn't my final row and it will be different all the time. (start row will remain the same)

I could enter '$B$2:$D11' $A$2:$A11', so it counts up for every line.
Or I could enter '$B$2:$D$1048576' and '$A$2:$A$1048576' (last row possible in Excel)

But isn't there a way to search the last row and then add it to the formula?
Something like '$B$2:D & last row'
For the 'last row' I would use:
Excel Formula:
=match(2,1/(D:D<>""),1)

This combination gives an error:
Excel Formula:
=$B$2:D & match(2,1/(D:D<>""),1)

And this will not work in the formula:
Excel Formula:
="$B$2:D" & match(2,1/(D:D<>""),1)
 
Upvote 0
I would just use something like
Excel Formula:
=INDEX(SORT(FILTER($B$2:$D$1000,$A$2:$A$1000=A2),1,-1),1,3)
and change the 1000 to a row that is below the max number of rows you would expect, without going over the top.
 
Upvote 0
I would just use something like
Excel Formula:
=INDEX(SORT(FILTER($B$2:$D$1000,$A$2:$A$1000=A2),1,-1),1,3)
and change the 1000 to a row that is below the max number of rows you would expect, without going over the top.
Yeah, that's what I did. I was just wondering if you could make such a combination.
I always want to be prepared on everything, like exceeding the max. set row :)

But it's more than good for now.
Thanks for the help.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

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