I want to group by Column1,Position and then perform the sum operation on value of Prix.
|Column1|Position|Prix|
|AA |1|1800|
|AA |1|5200|
|AA |2|1500|
|AA |1|300|
|BB |2|10|
|BB |2|100|
Can any one suggest me query to perform the above activity.
Thanks
Hi @Jyotika_Halai
Use Following Linq query
List (List of String) = (From p In dt.Select()
Group p By id=p.Item(“Column1”).ToString Into GroupA=Group
Select Convert.ToString(GroupA.Sum(Function(x) Convert.ToDouble(x.Item(“Prix”).ToString)))).ToList()
It will group element of Column1 and then using the Sum function it adds the values of Prix Column
Hi @jitendra_123
Thanks for your quick reply. I want to perform group by on two columns(Column1,Position).can you do it for two columns.
@Jyotika_Halai
otherwise you can do this using the Following steps.
- Use Yourdatatablevariable.DefaultView.ToTable(true,“Column1”) to get the unique values from the column.
- It gives the Unique values and it will store in a newdt data table variable.
- so use for each row for the newdt
- Get the values from it using row(“Column1”).tostring.
- Inside the for each row use another for each row for dt
- then get the values for it
- Compare both values in If Condition.
- Do the addition in the Then section.
Thanks & Regards