What expression should I put in my IF or WHILE statement to check if the current cell (Example A2) has the same value as the previous cell? (Example A1)

Hello friends from the UiPath community :smile:

(I apologise for the numerous edits on this post)
I am currently working on automating Microsoft Dynamics NAV 2013 Invoice Generation. I want the RPA to read data from excel, and copy paste it into NAV Sales Invoice Window, which I have already successfully read the data.

However, I don’t know how to copy and paste multiple running data or multiple sales invoice description into the same Excel Sales Invoice. What expression or activity should I use?

This is how the data looks like

Sample of the Final Sales Invoice Screenshot that I want
As you can see, the 3 descriptions of customer “2ROR-O-00000001” is in the same invoice.

What expression should I put in my IF or WHILE statement to check if the current cell (Example A2) has the same value as the previous cell? (Example A1)

I would appreciate any help. Thank you!

Hi @Sky_RPA

Welcome to community

Do you need to get all the duplicated value from the column If yes Try with this expression

(From p in DT.Select() where( From q in DT.Select() where q("ColumnNameOrIndex").Equals(p("ColumnNameOrIndex")) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Regards
Gokul

1 Like

Hi @Sky_RPA ,

Sorry but I’m not sure if I’ve understood your query since you titled it differently from the problem statement you have described so far.

Are you trying to say that you don’t know how to reference line items while they are inside of a For Each Row in DataTable or do you want to simply filter out Duplicate entries in Excel?

If you want to filter out duplicates, then based on which column do you want to remove the duplicates? I’m asking this since the rows themselves are actually unique, so if you want to remove duplicates you have to let us know on what basis you want the duplicates gone.

Kind Regards,
Ashwin A.K

1 Like

Hi @Gokul001 and @ashwin.ashok
I’m sorry if I wasn’t clear in my question :sweat_smile:

In the Excel, it states 3 rows for customer “2ROR-O-00000001”
with the difference being the “Description” (Example "ABC Sales Service, ABC Marketing Service and ABC Logistics Service)

Since they are the same customer, I want to write all 3 descriptions under 1 invoice.

:question:However, I am not sure what expression to put in my “IF” activity to check if the customer in the current row is the same as the customer in the previous row.

I hope I have clarified your doubt and thank you for taking your time off to help out!

Regards,
Sky

Hi @Sky_RPA ,

I’ve developed a workflow which doesn’t require you to rely on an If Activity.
Basically, we are grouping the items based on the first column and looping through the items in those groups →

image

Could you try adding the selectors within the inner loop give this workflow a try?
GroupSimilarCustomerDetails.xaml (8.4 KB)
GroupingExample.xlsx (8.0 KB)

Kind Regards,
Ashwin A.K

1 Like

Hi @ashwin.ashok :smile:
Yes it works!

In addition, may I know where I can read up more about the expression

dt_sampleData.AsEnumerable().GroupBy(Function(g) g("Sell to customer no.").ToString.Trim).ToList()

Thank you!

Hi @Sky_RPA ,

Here is a series of posts penned by ppr. He is a LINQ wizard who taught everyone on this forum how to develop LINQ, I hope you find it resourceful.

I also started penning my own series on LINQ, which you can check out if you are interested.

Kind Regards,
Ashwin A.K

1 Like

Hi @ashwin.ashok ,

Thank you for the resources!
I will check out your blog too.
Thank you so much :smile: :100:

Regards,
Sky :cloud:

1 Like

Hi @ashwin.ashok

In the xaml, you explained how to group them based on “Sell to customer no.”
In that group, all of the rows have this value “SHARED SERVICE - JAN 2022”.

What should I do or what expression should I use if I want UiPath to return the value “SHARED SERVICE - JAN 2022” (in a For Each loop)

Thank you.

Best regards,
Sky :cloud:

Hi @ashwin.ashok
What should I put in my expression if I want to group my data based on 2 different columns? Or how do I group values within a group?

Example:

In this case, I want to group my data based on

  1. The same customer no.
  2. Within the same customer no. the same External Document No.

And what expression should I write to get the final value the following values

  1. Description
  2. First group name (Example: External Document No. is 1000)
  3. Second group name (Example: Customer 1111)

Thank you!

Best regards,
Sky

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