Count specific column value

Hii All…
I have a Excel sheet which has given below.
image

In this Sheet i have to count the Rno column value according to the country column.
Like below image
image

Please help me with this all.

TIA…!:slight_smile:
Regards,
Soundarya

Hi,

Hope the following sample helps you.

image

 dt = dt.AsEnumerable.GroupBy(Function(r) r("country").ToString).Select(Function(g) dt.Clone.LoadDataRow({g.First().Item("id").ToString,g.Key,g.Count.ToString},False)).CopyToDataTable()

Sample20221018-3.zip (2.7 KB)

Regards,

1 Like

dt = dt.AsEnumerable.GroupBy(Function(r) Tuple.Create(r(“id”).ToString,r(“country”).ToString)).Select(Function(g) dt.Clone.LoadDataRow({g.First().Item(“id”).ToString,g.First().Item(“country”).ToString,g.Count.ToString},False)).CopyToDataTable()

It works Thankyou @Yoichi

1 Like

I have changed my sheet for the 2nd process. so, for that that the input looks like given below,
image

And the output is according to id and country column
like this,
image

Could you help me with this?

TIA…:slight_smile:
regards,
Soundarya

HI,

Can you try the following expression?

dt.AsEnumerable.GroupBy(Function(r) Tuple.Create(r("id").ToString, r("country").ToString)).Select(Function(g) dt.Clone.LoadDataRow({g.key.Item1.ToString,g.Key.Item2,g.Count.ToString},False)).CopyToDataTable()

Sample20221018-3v2.zip (2.8 KB)

Regards,

1 Like

Hi @Yoichi

Thank you so much for the solution

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