For each loop in group wise

Hi Brilliant Team, @Yoichi @supermanPunch @ppr
I am facing an issue to build my expectation. Please assist me.
Here is my dt
image
Output looks:
image
What I want to do?
After making the output (Like output image where filter column will be only name). I want to use for each loop activity. In for each loop first bot proceed all “flower” once flower will finish bot will proceed “book” and once book finish bot will proceed “Pen” and so on.
How can I achieve this?

Thanks in Advanced.

1 Like

only first column has been sorted and other two columns are unsorted(same as input) , is this your required output??
Seems a bit complicated from logical point of view , can you please explain if there is any relations between the three columns otherwise its confusing …

1 Like

Hi @Jesmine,

Go with the approach @saurabhB said. That is the most robust way to get what you want.

I do think you will also want to sort the other two columns when you make such groups corresponding to the name column (Sort which affects all columns).

You can either use the Index ( in your case 1, or the name of the column)
If the column is string, sort goes from a-z or z-a

When using a dummy data :

SortDataTable.xaml (8.4 KB)

2 Likes
1 Like

Hey @Jesmine

Try using the Group Linq

dt_input.AsEnumerable.GroupBy(Function(row) row("Name").ToString)

The above statement will provide you a collection of grouped items (3items for above example) with Name as key

Store the above result in a variable & use it in foreach collection & then you will be going for one more foreach inside it.

What I can suggest is, if you can let us know what’s the actual business logic after grouping what should be done. We can think of or build using Linq itself or may be a better logic than nested for-each just if that’s possible.

Hope this helps

Thanks
#nK

1 Like

Hi Thanks all for your wonderful supports. Can you tell me how can I get the first value from the group? like first flower then book and then pen like this

1 Like

Hey @Jesmine

Just set the Foreach type argument to grouping

And you can get it from item as item.key which will give you the group identifier value.

Thanks
#nK

Thanks, Any dummy workflow for this and get first record from group?

Thanks

@Jesmine

Try below expression.

dtOutput = ( From row in dtInput 
Group row by a = row("Name").ToString.Trim into grp = Group
Where grp.Count > 1
Select grp.First).CopyToDataTable

Thanks. @lakshman
I have did this thing but I am getting error if I will use First. Where is the wrong?
image

@Jesmine

Looks like a typo there

From instead of form

1 Like

@Jesmine

As @jeevith mentioned, change the Form to From and also add where condition grp.Count > 1. Use the expression I mentioned above and just change the column name as per your input file.

1 Like

@Jesmine

Is about expression working ? Do you have any other queries ? If not please close this thread by marking appropriate post as solution.

Hi @Jesmine ,

If you were looking for a short sample workflow, then here you go →

Hana.xaml (12.4 KB)

Kind Regards,
Ashwin A.K

1 Like

Hi Laksman, @ashwin.ashok
Thanks for your valuable support. Can you tell me
In my for each loop want to do some action. Among all of the action I need to click a button single time and rest of the action will be normal for each loop procedure.
Like
image
inside for each
Like for row(“Name”).tostring = “Flower” (Each group last item)
Then Click 1 and click 2 and click 3 and so on.
then again row(“Name”).tostring = “Flower” (flower=flower)
ignore click 1 it will click 2 and click 3 and so on.

Again it will check
row(“Name”).tostring = “Book” (Each group last item) (Book = book)
Then Click 1 and click 2 and click 3 and so on.
then again row(“Name”).tostring = “Book” (Book =Book)
ignore click 1 it will click 2 and click 3 and so on.

Continue for all data like this.
Please assist me. I am stuck on this. Any suggestion will be appreciated.

Thanks Brilliants

Jesmine

Thanks but it will be look likes
image

Flower is fine but book and pen is not the expectation.

Thanks

1 Like

Hey @Jesmine

I’m thinking this may just due to the logging issue,

Looks like your grouping worked fine

Thanks
#nK