Urgent action needed Excel related Logical question

Suppose if we have 5 columns with duplicated values in 4 columns then we need to Sum all values of 5th column. How can we do it using UiPath activities

@travellerdream_m

Can you please elaborate or show some input and output that is expected

Cheers

employee id org salary project-------------> These are headers
Chan 22 CAG 123 stan
Chan 22 CAG 467 stan
Chan 22 CAG 765 stan
Sure 23 DEA 879 leka
Ram 43 FEC 657 norm

In this example, duplicate rows need to be removed, and under salary, whatever the values are, they need to be summed up and put into a single value.

Output:
employee id org salary project
Chan 22 CAG 1355 stan
Sure 23 DEA 879 leka
Ram 43 FEC 657 norm

@travellerdream_m

Dtclone = dtbuild.Clone()

Please use this linq query in assign


Dtclone = (From d In DtBuild.AsEnumerable()
Group d By k=d("id").toString.Trim Into grp = Group
Let sum = grp.sum(function(x) cdbl(x("Salary").ToString)).ToString
Let k1 = grp.select(function(x) x("Name").ToString).First()

Let k2 = grp.select(function(x) x("org").ToString).First()

Let k3 = grp.select(function(x) x("employee").ToString)

Let ra = New Object(){k3,k,k2,sum,k1}
Select r = DtClone.Rows.Add(ra)).CopyToDataTable()

Cheers

1 Like

Thank you Anil. However is there any way that we can do via UiPath native activities…!?

Thank you Anil. However is there any way that we can do via UiPath native activities.

@travellerdream_m

You can uniquetable= dt.defaultview.ToTable(true,“id”) will give you a datatable with unqiue id

Now use for looop on this unqiue id and then use filter datatable and get only the specific id and then in loop through filtered table and use sum = sum + cdbl(currentrow(“salary”))

Then after the inner loop use add datarow with the values needed

Cheers

have a look here:

at the first part a NON-LINQ approach is desribed using DefaultView and filtering

1 Like

Sth similar that @Anil_G i @ppr suggested:

Code for str_Salary:

dt_Temporary.AsEnumerable.sum(Function(x) Convert.ToInt32(x("salary").ToString)).ToString

But I would go with Linq and leave some annotation in the assign to explain what it is doing (basically it does the same when we look at the steps).

My workflow just looks complicated (a lot of steps) and you will get the same results with LINQ.