How to get all the values in a for each loop using group by on a specific column

I have been using for each loop on a Excel and extracting the values to fill into SAP, and its working fine as each time it extracts one row and fills the values into SAP.

But, I am looking to use the group by on a specific column “ID_No” and get all the similar “ID_No” value in a single for each loop to fill up the values in SAP.
Book1.xlsx (9.7 KB)

I am trying to get Debit_Val and Credit_Val in a single for each, so that while uploading the values in SAP i can fill the Debit and credit value in SAP using a single for each.

Please Suggest


Share what is the output required


Hi @mayankjha986

Try the below expression

(From G In ReadDT.AsEnumerable
Group By O = New With {Key.K = G.Item("ID_No"), Key.U = G.Item("ID_No")} 
Into Group Select Group(0)).ToArray().copytodatatable()

Test-GroupBy.xaml (5.7 KB)


Required Output is:

To get all the similar ID_No in one for Each,
For Eg: If ID_No - “122604” is selected in for Each, Is it possible to get all the 3 similar rows with the same ID_No in one For Each.
So that when using the Values in SAP i can use like row(“Debit_Val”).To_String

Please Suggest


Check below to get the unqiue values from the datatable


I have multiple A’s and B’s but I keep the unqiue values to for example DatatableUnqiueValues

Now loop that datatable using foreach

Use Filter Datatable activity to the main datatable let’s say Dt

Where the column is Column1 = row(“Column1”).ToString

So it will filter all the rows which matches

After that you can use another For Each row to fill the data to SAP

So loop into loop will work in this scenario

Try and let us know if you face any issue

Hope this will help you


Have a Look Here for Different approaches grouping Data

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