The solution is to join the original data with itself, using a minimum aggregation to calculate Earliest Date.
From this starting data in a Query called Query1
:
ID,Date
501,01/01/2017
203,08/06/2015
304,01/04/2014
501,01/01/2016
201,01/02/2015
501,01/08/2015
Join the data with: Combine > Merge Queries (aka "Join") > Merge Queries as New (to avoid modifying Query1)
Pick Query1
ID column each time, and leave the default Left Outer join Kind:
Next, choose Transform > Structured Column > Aggregate, and pick "Count of Date" (It would be better if the UI suggested a minimum aggregation, but we can fix that by touching the code directly).
Next, turn on the Formula Bar (View > Layout > Formula Bar) and edit the formula to replace List.Count
with List.Min
. Rename the new column, and you're done!
My full "M" formulas:
Query1:
let
Source = Table.PromoteHeaders(Csv.Document("ID,Date
501,01/01/2017
203,08/06/2015
304,01/04/2014
501,01/01/2016
201,01/02/2015
501,01/08/2015"))
in
Source
Merge1:
let
Source = Table.NestedJoin(Query1,{"ID"},Query1,{"ID"},"NewColumn",JoinKind.LeftOuter),
#"Aggregated NewColumn" = Table.AggregateTableColumn(Source, "NewColumn", {{"Date", List.Min, "Earliest Date"}})
in
#"Aggregated NewColumn"