Help with creating a Linq statement


The output I need:

And so on…

The Unit,ID and Name must be same. I have tried myself with different Linq statements but I cant make it work.

Is it possible to sort it like the output shows in one single Linq statement and pass it along to a for each activity?

Have read this:

But dont really know how to implement it.

If I explained poorly I can elaborate.

maybe I have misinterpretated (not sure what about 3, DA 123123)

Lets assime following:

  • group the data on 3 keys
  • take from all group the first member

(From d in dtData.AsEnumerable
group d by k1=d(0).toString, k2=d(1).toString, k3=d(2).toString into grp=Group
Select g=grp.First()).toList

returns a list of datarows

Do get the output I want like above im currently doing it like shown below.
@ppr How to I implement your solution, dont know how to set it up.


your implementation has a look that it targets a different requirement. It will help if you provide a complete described output sample on the given input sample data from above. Based on this we can better check the solution options. Thanks

@ppr The output I show in the post at the top is what I need to be able to process column B and E easier. The input are datatables that look like something like this:
I need it filtered on column A,C and D like the output shows:

That’s why I am doing it like in my flow above. I just wonder if I can do it with less code.
You provided a linq statement. But I think that I need to loop through the original datable so I can process column B and E easier. I need to compare column B and E with eachother but only when the values at column A, C and D are of the same value/type.

Right now I sorting it in two steps, first at Remittent and then at Payment Unit.

Note that the excel example is just and example with fabricated column names.

this input table from your input:

will have an output:
firstly described with:

And so on can be interpretated in multiple directions

Second output is different:

So may we ask you on:
for given input

please give us complete description of given output


Otherwise you can use the LINQ within an assign and check how close it is to your expected result.

we want to find out if your case matches to a sort or to a group by task. For this we do need your input. Thanks


I will try to explain again, the Input Datatable has different values each days. The datatable needs to be sorted at column A,C and D(these column rows must have the same values).

This is why the output will vary from day to day. But to make it easier to understand.

Lets say that I have this Input:

I want to use this within a for each activity to get this:

Then this:

and lastly this:


In the for each activity I want to do some calculations based on these filtered datatables.

I hope this helps.


  • assign activity:
    left side: TableList - Datatype: List(Of DataTable)
    right side:
    (From d in dtData.AsEnumerable
    group d by k1=d(0).toString, k2=d(2).toString, k3=d(3).toString into grp=Group
    Select g=grp.CopyToDatatable).toList

  • For each activity: table - in TableList #TypeArgument: Datatable

    • now you can process the groups e.g. with a for each row activity

in case of the order of the groups is required we can modify the LINQ by applying some orderings

1 Like

Create two LINQs:
One for all the unique list of Company names -
CompanyVariable = Dt_Table.AsEnumerable.Select(Function(x) x.item(“Name”).ToString).Distinct.ToList
And the other for the result you want -
For each row(DataType String)
Dt_Loop = Dt_Table.AsEnumerable.Select(Function(x) x.item(“Name”).ToString.Trim = CompanyVariable))

Note: My UiPath isn’t working for some reason, so I wasnt able to test them out, try playing around with the keywords and see what works.

-Ashwin A.K(Speridian Technologies)

1 Like


Perfectly, exactly what I needed. Thank you!

Just a question what difference does the “First” make?
Select g=grp.CopyToDatatable).toList
Select g=grp.First()).toList

I will try this out too.

Thank you.

the grp.First()).toList was coming from a misinterpretation of the case and is taking the first row from group and adds it to the final list

Select g=grp.CopyToDatatable).toList is creating a datatable from the group member rows and adds it to the final list (in that case the tablelist)

1 Like

Okay, thank you :slight_smile:

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