Group By Two Columns using the Linq query

Hello,

can anyone help me with this query?

dt.AsEnumerable.GroupBy(Function(r) r("ContractNumber").ToString).Select(Function(g) dtResult.LoadDataRow({g.Key,g.Where(Function(r) r("Status").ToString="Not-Submitted" OrElse r("Status").ToString="Submitted" ).Count,g.Where(Function(r) r("Status").ToString="Submitted").Count,g.Where(Function(r) r("Status").ToString="Not-Submitted").Count, (100*(g.Where(Function(r) r("Status").ToString="Submitted").Count/g.Where(Function(r) r("Status").ToString="Not-Submitted" OrElse r("Status").ToString="Submitted" ).Count)).ToString+"%" },False)).CopyToDataTable

I am trying to add another column name with the **Contract Number** which is called “Name”

so when it’s written the ContractNumber data, I need it to write the Name also.

The contract number and Name are related to each other.

Thank you

.

@coder

You can use r("Contractnumber").ToString + r("Name").ToString

Cheers

Thank you for your reply, but it’s not working.
i didn’t get the result of the name

@coder

Can you please explain what is not working and what you are getting and what you need

you asked for group by…so you want the data also to be visible in output?

cheers

image

this is the output, but I wanted it to be in the Name column.

I want this output

image

@coder

If you need to add it as separate column then try this


dt.AsEnumerable.GroupBy(Function(r) r("ContractNumber").ToString).Select(Function(g) dtResult.LoadDataRow({g.Key,g.First()("Name").ToString,g.Where(Function(r) r("Status").ToString="Not-Submitted" OrElse r("Status").ToString="Submitted").Count,g.Where(Function(r) r("Status").ToString="Submitted").Count,g.Where(Function(r) r("Status").ToString = "Not-Submitted").Count, (100*(g.Where(Function(r) r("Status").ToString="Submitted").Count/g.Where(Function(r) r("Status").ToString = "Not-Submitted" OrElse r("Status").ToString="Submitted" ).Count)).ToString+"%" },False)).CopyToDataTable

cheers

1 Like

Its working , Thank you for your help

1 Like

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