Consolidate data from a table using Linq

@Lynx,

Here you go the LINQ query:

(From row In dtInput.AsEnumerable()
 Group row By usuario = row.Field(Of String)("usuario") Into userGroup = Group
 Select dtOutput.LoadDataRow(New Object() {
     usuario,
     userGroup.Select(Function(r) r.Field(Of String)("analisis 1")).FirstOrDefault(Function(a) Not String.IsNullOrEmpty(a)),
     userGroup.Select(Function(r) r.Field(Of String)("analisis 2")).FirstOrDefault(Function(a) Not String.IsNullOrEmpty(a)),
     userGroup.Select(Function(r) r.Field(Of String)("analisis 3")).FirstOrDefault(Function(a) Not String.IsNullOrEmpty(a))
 }, False)).CopyToDataTable()

Input:

Output:

Sample Code:
DataConsolidation.zip (11.4 KB)

Thanks,
Ashok :slight_smile:

1 Like