Forum Discussion
Compare multiple date/time columns and find the latest date
- 6 years ago
Hi lightw0rks ,
you can add a custom column with the following formula:
It allows you to add additional Date columns as well. It skips the first column of the table.
But it could easily be changed to a solution where the date-columns are hardcoded if the dynamic solution is not desired.
This is the code to try out:let Source = #table( {"ID", "Date1", "Date2", "Date3"}, List.Zip( { {"1", "2", "3", "4"}, {"01/07/2017 09:00", "01/07/2017 10:00", "01/07/2017 09:30", "01/07/2017 09:45"}, {"10/09/2020 12:00", "null", "null", "03/08/2020 09:35"}, {"12/03/2019 11:00", "null", "03/05/2020 09:00", "null"} } ) ), #"Changed Type" = Table.TransformColumnTypes( Source, {{"Date1", type datetime}, {"Date2", type datetime}, {"Date3", type datetime}} ), #"Added Custom" = Table.AddColumn( #"Changed Type", "Custom", each List.Max(List.Skip(Record.FieldValues(_))) ) in #"Added Custom"
Hi lightw0rks ,
you can add a custom column with the following formula:
It allows you to add additional Date columns as well. It skips the first column of the table.
But it could easily be changed to a solution where the date-columns are hardcoded if the dynamic solution is not desired.
This is the code to try out:
let
Source = #table(
{"ID", "Date1", "Date2", "Date3"},
List.Zip(
{
{"1", "2", "3", "4"},
{"01/07/2017 09:00", "01/07/2017 10:00", "01/07/2017 09:30", "01/07/2017 09:45"},
{"10/09/2020 12:00", "null", "null", "03/08/2020 09:35"},
{"12/03/2019 11:00", "null", "03/05/2020 09:00", "null"}
}
)
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"Date1", type datetime}, {"Date2", type datetime}, {"Date3", type datetime}}
),
#"Added Custom" = Table.AddColumn(
#"Changed Type",
"Custom",
each List.Max(List.Skip(Record.FieldValues(_)))
)
in
#"Added Custom"
Thanks, that's great!
I needed a harcoded solution as I had a few more columns going on in my data so I modified it slightly:
List.Max(Record.FieldValues(Record.SelectFields(_, "Date1", "Date2", "Date3")))