Forum Discussion
LC_2020
Jan 16, 2020Copper Contributor
Combining data from multiple rows into a single row taking earliest date
I have a data set that looks like this: ID Name Driver's Liscence Submission Date Approval Date 341 Kenner, Jen 32214 9/16/19 9/15/19 318 Kenner, Jen 32214 9/18/19 9/19/19 ...
SergeiBaklan
Jan 18, 2020Diamond Contributor
For such model
If with formulas:
Select unique names
=IFERROR(INDEX($C$4:$C$7,AGGREGATE(15,6,1/(COUNTIF($I$3:$I3,$C$4:$C$7)=0)*(ROW($C$4:$C$7)-ROW($C$3)),1)),"")
Driver license
=IFNA(INDEX($D$4:$D$7,MATCH($I4,$C$4:$C$7,0)),"")
Submission date (earliest in list)
=IFERROR(AGGREGATE(15,6,1/($C$4:$C$7=$I4)*$E$4:$E$7,1),"")
Approval date (latest one)
=IFERROR(AGGREGATE(14,6,1/($C$4:$C$7=$I4)*$F$4:$F$7,1),"")
Combined ID:
=TEXTJOIN("",TRUE,IF($C$4:$C$7=$I4,$B$4:$B$7,""))
and drag all down till empty cells appear.
If with Power Query:
Query the list, Group by Names with proper aggregations on other columns, return back adding some cosmetic:
let
Source = Excel.CurrentWorkbook(),
SourceList = Source{[Name="SourceList"]}[Content],
PromotHeaders = Table.PromoteHeaders(
SourceList,
[PromoteAllScalars=true]
),
FilterNulls = Table.SelectRows(
PromotHeaders,
each ([Name] <> null)
),
ChangeType = Table.TransformColumnTypes(
FilterNulls,
{
{"ID", type text},
{"Name", type text},
{"Driver's Liscence", type text},
{"Submission Date", type date},
{"Approval Date", type date}
}
),
GroupNames = Table.Group(
ChangeType,
{"Name"},
{
{"ID", each Text.Combine([ID]), type text},
{"Driver's Liscence", each List.First([#"Driver's Liscence"]), type text},
{"Submission Date", each List.Min([Submission Date]), type date},
{"Approval Date", each List.Max([Approval Date]), type date}
}
),
ReorderColumns = Table.ReorderColumns(
GroupNames,
{"ID", "Name", "Submission Date", "Approval Date"}
)
in
ReorderColumns