This is my excel sheet. I read it and my data table name is “dtResultsPage”.
I do not know how to group “Model” column values according to the first 4 letters (320i,318i,320d etc.) with linq code
This is my excel sheet. I read it and my data table name is “dtResultsPage”.
I do not know how to group “Model” column values according to the first 4 letters (320i,318i,320d etc.) with linq code
Could you send the sample excel file
sample.xlsx (21.4 KB)
hi @170290064
try this
Use an Assign activity:
(Variable) dtInputData=
(From row In dtInputData.AsEnumerable()
Group row By ModelPrefix = row(“Model”).ToString().Substring(0, 4) Into Group
Let GroupedModels = String.Join(“,”, Group.Select(Function(r) r(“Model”).ToString()))
Select dtInputData.Rows.Add({ModelPrefix, GroupedModels})).CopyToDataTable()
This is not what i want. It might be 30 different series. I do not want to make it manuel one by one.
I needed to make it with linQ methods
From dt In dtResultsPage
Group dt By ModelPart = System.Text.RegularExpressions.Regex.Match(dt(“Model”).ToString,“\d*\w”).Value.ToString Into grp = Group
Select grp
You can try this to group based on model numbers like 320i or 318i etc
Try using this @170290064 ,
Assign groupedData= dtResultsPage.AsEnumerable.GroupBy(Function(row) row.Field(Of String)(“Model”).Split(" "c)(0))
type for the variable groupedData : IEnumerable
@170290064 Try importing System.Text.RegularExpressions .
dtInputData = dtResultsPage
@170290064 Check the ‘Import’ panel which is to the left of the ‘Variable’ panel
@170290064 Try using this in the assign activity,
Assign groupedData= dtResultsPage.AsEnumerable.GroupBy(Function(row) row.Field(Of String)(“Model”).Split(" "c)(0))
type for the variable groupedData : IEnumerable
If you group the data, it wont be able to get a proper datatable back since it will be in a collection format. one method is to use a for each getting each item in groupedData and writing the currentItem to excel
dtInputData is not declared in variables or its scope is not reachable there