How to return cell header with latest date

Sian1

Board Regular
Joined
Nov 9, 2009
Messages
90
Hi, i have 4 columns with various date on it, how could i write a formula to return the header named based on the latest date

ABCDReturn Value
1/20/20201/20/20201/23/2020D
7/11/20195/28/20198/6/20208/10/2020D
7/5/20216/23/20216/23/2021B
7/5/20211/14/20211/14/20211/15/2021A
8/10/20201/3/20201/6/2020B
10/10/20196/23/202110/27/2020C
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Assuming you actually have A, B, C in the first row then this in row 2 and fill down:

Excel Formula:
=INDEX($A$1:$D$1,MATCH(MAX(A2:D2),A2:D2,0))

$scratch.xlsm
ABCDE
1ABCDReturn Value
21/20/20201/20/20201/23/2020D
37/11/20195/28/20198/6/20208/10/2020D
47/5/20216/23/20216/23/2021B
57/5/20211/14/20211/14/20211/15/2021A
68/10/20201/3/20201/6/2020B
710/10/20196/23/202110/27/2020C
Sheet1
Cell Formulas
RangeFormula
E2:E7E2=INDEX($A$1:$D$1,MATCH(MAX(A2:D2),A2:D2,0))
 
Upvote 0
I'm sorry, I didn't notice what forum this was in, I was just listing "Unanswered threads." I don't know PQ so hopefully someone else will come along.
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"A", type date}, {"B", type date}, {"C", type date}, {"D", type date}}),
    AddCol = Table.AddColumn(ChangeType, "Latest Date", each Table.FromColumns({Table.ColumnNames(ChangeType),Record.ToList(_)})),
    TransformCol = Table.TransformColumns(AddCol, {"Latest Date", each Text.Combine(Table.SelectRows(_, (x)=> x[Column2] = List.Max(_[Column2]))[Column1],", ")})
in
    TransformCol

Book1
ABCDEFGHIJK
1ABCDABCDLatest Date
21/20/20201/20/20201/23/20201/20/20201/20/20201/23/2020D
37/11/20195/28/20198/6/20208/10/20207/11/20195/28/20198/6/20208/10/2020D
47/5/20216/23/20216/23/20217/5/20216/23/20216/23/2021B
57/5/20211/14/20211/14/20211/15/20217/5/20211/14/20211/14/20211/15/2021A
68/10/20201/3/20201/6/20208/10/20201/3/20201/6/2020B
76/23/202110/10/20196/23/202110/27/20206/23/202110/10/20196/23/202110/27/2020A, C
8
Sheet1
 
Upvote 0
Table.TransformColumns(AddCol, {"Latest Date", each Text.Combine(Table.SelectRows(_, (x)=> x[Column2] = List.Max(_[Column2]))[Column1],", ")})
Hi, May i know what the Column 2 and Column 1 means? i am having a problem as tables have more data than the one that i have shown here. How could i list out the dates that i want to compare?

thanks so much for the help
 
Upvote 0
Look at the tables in the [Latest Date] column of the AddCol step. Column1 contains the table column names and Column2 contains the dates.
 
Upvote 0
Yeah I did find out however I still get the error saying it couldn't find column1. Do you know why?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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