for example in this dt
unify rows that are the same like columna1 1.1 values and columna2 123 and SUM col3 “cantidad”
so the result should be
how to do it?
for example in this dt
unify rows that are the same like columna1 1.1 values and columna2 123 and SUM col3 “cantidad”
so the result should be
how to do it?
Hi @amy93amanda ,
There are many posts in here, which provides the relevant solution to your requirement as it is a Group By and Sum case. One of the posts is mentioned below :
Also, Find below Detailed methods on Grouping :
Hi @amy93amanda,
Use the below expression in assign activity:
(From d In Dt.AsEnumerable Group d By k=d(“Columna1”).toString.Trim Into grp=Group Let sumVal= grp.Sum(Function (x) CDbl(x(“Cantidad”).toString)) let rows=grp.FirstOrDefault Let ra = New Object(){k, rows(“Columna2”).tostring, sumVal} Select Dt.Rows.Add(ra)).CopyToDataTable
Hi @amy93amanda ,
First create a dt_Grouped datatable variable and clone with input table as below in assign,
dt_Grouped = dt_Input.Clone()
Then in second assign use below linq,
dt_Grouped = (From row in dt_Input.AsEnumerable
Group row by k=row("Columna1").ToString.Trim Into grp=Group
Let total= grp.Sum(Function(x) CDBl(x("Cantidad").ToString.Trim)).ToString
Let result = New Object(){grp(0)("Columna1").ToString,grp(0)("Columna2").ToString,total}
Select dt_Grouped.rows.add(result)).CopyToDataTable
Hope this may help you
thank so much, mark as solution but i implement because actually need multiple columns to group by beside the first thanks!!
for this
(From d In tabla.AsEnumerable Group d By k=d(“Columna1”).toString.Trim , k2=d(“Columna2”).toString.trim Into grp=Group Let sumVal= grp.Sum(Function (x) CDbl(x(“Cantidad”).toString)) let rows=grp.FirstOrDefault Let ra = New Object(){k, rows(“Columna2”).tostring, sumVal} Select tabla.Rows.Add(ra)).CopyToDataTable
thanks also to the rest to find other threads an info to learn!!
also works!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.