Look for the largest value if condition met

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hello All,

Can someone please help me with a formula to find the largest time value in the scenario below?

[TABLE="width: 203"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD="align: right"]09:06:15 [/TD]
[TD]To City[/TD]
[/TR]
[TR]
[TD="align: right"]09:22:11 [/TD]
[TD]To City[/TD]
[/TR]
[TR]
[TD="align: right"]09:23:04 [/TD]
[TD]To City[/TD]
[/TR]
[TR]
[TD="align: right"]09:27:51 [/TD]
[TD]To City[/TD]
[/TR]
[TR]
[TD="align: right"]09:28:53 [/TD]
[TD]Dead[/TD]
[/TR]
[TR]
[TD="align: right"]10:27:05[/TD]
[TD] Dead[/TD]
[/TR]
[TR]
[TD="align: right"]10:28:17[/TD]
[TD] Dead[/TD]
[/TR]
[TR]
[TD="align: right"]16:25:08 [/TD]
[TD]Dead[/TD]
[/TR]
[TR]
[TD="align: right"]22:01:08[/TD]
[TD] Dead[/TD]
[/TR]
[TR]
[TD="align: right"]22:09:54[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]22:15:32[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]22:18:59[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD="align: right"]22:22:49[/TD]
[TD] To City[/TD]
[/TR]
[TR]
[TD="align: right"]22:36:07[/TD]
[TD] To City[/TD]
[/TR]
[TR]
[TD="align: right"]22:36:54[/TD]
[TD] To City[/TD]
[/TR]
[TR]
[TD="align: right"]22:53:04[/TD]
[TD] To City[/TD]
[/TR]
</tbody>[/TABLE]

In the data above, I need formula to give me value 9:27:51. I tried looking for largest value in column A if values in column B for next 20 rows are same. It gives me answer 22:53:04. This is not what I want. I want the answer to be 9:27:51. Is it possible?

Thanks
Asad
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
you can try PowerQuery

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Column1[/td][td=bgcolor:#5B9BD5]Column2[/td][td][/td][td=bgcolor:#70AD47]Column2[/td][td=bgcolor:#70AD47]max[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
09:06:15​
[/td][td=bgcolor:#DDEBF7]To City[/td][td][/td][td=bgcolor:#E2EFDA]To City[/td][td=bgcolor:#E2EFDA]
09:27:51​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]
09:22:11​
[/td][td]To City[/td][td][/td][td]Dead[/td][td]
22:01:08​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
09:23:04​
[/td][td=bgcolor:#DDEBF7]To City[/td][td][/td][td=bgcolor:#E2EFDA]
0​
[/td][td=bgcolor:#E2EFDA]
22:18:59​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td]
09:27:51​
[/td][td]To City[/td][td][/td][td]To City[/td][td]
22:53:04​
[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
09:28:53​
[/td][td=bgcolor:#DDEBF7]Dead[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
10:27:05​
[/td][td]Dead[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
10:28:17​
[/td][td=bgcolor:#DDEBF7]Dead[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
16:25:08​
[/td][td]Dead[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
22:01:08​
[/td][td=bgcolor:#DDEBF7]Dead[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
22:09:54​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
22:15:32​
[/td][td=bgcolor:#DDEBF7]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
22:18:59​
[/td][td]
0​
[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
22:22:49​
[/td][td=bgcolor:#DDEBF7]To City[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
22:36:07​
[/td][td]To City[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
22:36:54​
[/td][td=bgcolor:#DDEBF7]To City[/td][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]
22:53:04​
[/td][td]To City[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type time}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Column2"}, {{"max", each List.Max([Column1]), type time}},GroupKind.Local)
in
    #"Grouped Rows"[/SIZE]
 
Upvote 0
Thanks for solution sandy666

Does this mean that there is no formula that can achieve this?
 
Upvote 0
I don't know :) but maybe someone else will give you formula solution
Thanks for the solution anyway.. If I do not get any formula, I will try to use this power query. I have never used this before, hence a bit reluctant.
 
Upvote 0
Finally worked it out. Probably not the best solution, but it will do for the time being.

Code:
=INDEX(A2:A15,MIN(IF(B2:B15<>B1,ROW(B2:B15)-ROW(B1))))
entered with ctrl+shift+enter
 
Upvote 0
If you have Excel 2010 or later here is a formula using AGGREGATE that doesn't require CTRL-SHIFT-ENTER, just ENTER.
Excel Workbook
ABCD
19:06:15To City9:27:51
29:22:11To City
39:23:04To City
49:27:51To City
59:28:53Dead
610:27:05Dead
710:28:17Dead
816:25:08Dead
922:01:08Dead
1022:09:540
1122:15:320
1222:18:590
1322:22:49To City
1422:36:07To City
1522:36:54To City
1622:53:04To City
Sheet
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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