How to filter with linQ code?

I made this excel a data table sheet after Read Range Workbook

Now i want to make it a new data table from it where there are “Model” and “Fiyat” .

Models which starts the same first 4 letters(“Model”) is enough to be like in the following :point_down:

NOTE : I asked the kinda same question before but answers were not clear. Also i need to make it with LinQ Codes

(From row In dtInput.AsEnumerable()
Group row By ModelPrefix = If(row(“Model”).ToString().Length >= 4, row(“Model”).ToString().Substring(0, 4), row(“Model”).ToString()) Into Group
Let GroupedFiyat = String.Join(“,”, Group.Select(Function(r) r(“Fiyat”).ToString()))
Select dtOutput.Rows.Add({ModelPrefix,GroupedFiyat})).CopyToDataTable()

  1. The above code goes through each row in the datatable and group based on first 4 letters in the string if the length of value in Model is 4 or more, else it takes the string as it is.

  2. We assign a variable ModelPrefix that stores the substring used to group the value

  3. Using Let we assign another variable GroupedFiyat that stores the list of values grouped. We convert the list to a string by joinning it based on comma.

  4. Using Select we add Rows to the output datatable to columns Model and Fiyat

1 Like

Thanks a lot for the explanation :robot: :slightly_smiling_face: :facepunch: :+1:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.