Group two column values with unique column

Hi,

I have three columns based on column A i need to join the remaining two columns as shown below.

Column A startpage Endpage

Item 1 1 1

Item 2 3 3

Item 1 4 4

Actual output i want is

Column A Range

Item1 1-1, 4-4

Item2 3-3

Thanks in advance

Regards,
Navya

image

Regards,
Navya

Hi,

Hope the following sample helps you.

dtResult = dt.AsEnumerable.GroupBy(Function(r) r("Column A").ToString).Select(Function(g) dt.LoadDataRow({g.Key,String.Join(",",g.Select(Function(r) r("startpage").ToString+"-"+r("endpage").ToString))},False)).CopyToDataTable

Sample20221119-1aL.zip (2.8 KB)

Regards,

Hi @Navya_Nadakuduti

How about this expression

(From d In DtBuild.AsEnumerable
Group d By k=d("Column A").toString.Trim Into grp=Group
Let B =String.Join(",",grp.Select(Function (x) x("Start Page").toString.Trim+"-"+x("End Page").toString.Trim))
Let ra = New Object(){k, B}
Select DtClone.Rows.Add(ra)).CopyToDataTable

Check out this XAML file

LinqGroupby.xaml (10.0 KB)

image

Regards
Gokul

Hi Gokul,

Thank you so much for your solution, code is working as expected.

Best regards,
Navya.

Great @Navya_Nadakuduti

Kindly close this topic by mark as solved. It will help for other too.

Regards
Gokul

Hi Yoichi,

Thank you so much for your solution, code is working as expected.

Best regards,
Navya.

1 Like

Kindly put closure to this topic by marking it as solved. It will help for other folks too

Kindly update the correct post as solved @Navya_Nadakuduti

1 Like

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