Data Table : logic to process data

I have a data table that has some data, say DataTable 1.

Also, I have done some calculations for count values; let’s say,
First_Count = 20,
Second_Count = 10,
Third_Count=10.

I have to do some desktop automation for each data point in DataTable 1.
For the first 20 data points as per the First_Count value, I have to do a different method of processing. For the second 10 data points, as per the Second_Count value, I have to use a different method of processing. Like wise, the same goes for the next 10 values as per the Third_Count value.

Can someone help me with the logic for this?

TIA,
Soundarya

Are the First_Count, Second_Count and Third_Count available in DataTable 1 as well? Or what is the relationship between them and your data?

Thank you so much for willing to help :slight_smile:

Those values are not in the DataTable1.
those values are process the data for Datatable1.
eg,
let say DataTable1.rows.count = 40.
the first 20 row values have to be assigned to person 1 to process
the next 10 row values have to be assigned to person 2 to process
the next 10 row values have to be assigned to person 3 to process

TIA:)

Well as long as you have those counts that you mentioned, you can take a static approach using Else If statement.

The idea is to iterate through your DT as usual and inside the iteration you have to check where exactly is the Index of the currentRow from the DT. For example if the index is smaller than 20 (First_Count), then you are on the First_Count, if the index is greater than First_Count (20 in this case), but smaller than 30 (First_Count+Second_Count), then you are on the Second_Count set of actions and so on.

You can also opt to a more dynamic approach in case you don’t know the number of counts by saving the list of counts in a config file or having it been given as input from the user. Let’s suppose in this scenario that you use a config file and your counts will be 10,10,30,10 meaning first 10, the next 10, the next 30 and the last 10. You will read this as a string first, so it will be “10,10,30,10”, then you will split it and convert it into a list of Strings. so you will have List (of String) from {“10”,“10”,“30”,“10”}. Now what you can do basically is to iterate through each count and for each count you have to iterate through the datatable and perform the actions. Please note that for this approach you also need your actions to be dinamically done based on the counts that you have.

As well for the first approach where you have only 3 counts at all times, you can create a list out of them, iterate through it and use LINQ to take the exact number of elements you need each time.

Please let me know if you need more insights on this.

I have tried with the else if condition, but it always shows that the “condition is a required” error. The condition I have used as the first condition is intial_count1 < first_count.
Here intial_Count1 = 0, and for the second condition, initial_Count2 < Second_Count, here initial_Count2 =0.

Can you also provide a screenshot of UiPath Studio?

This error is generated in case you have a branch where you did not add your condition, can you double-check if all If / Else If branches have a condition?

Hi, now it’s working Thank you.
But the logic is not helpful,
For the second process it is picking the first-row data.
but it’s needs to be picking the 21st data row.

No worries, that can be fixed too.
For each Row in Data Table has a property called Index.
properties
You can create a variable there and use that for your Else If.

Basically you will need the following conditions:

  • First_Count: Index <= First_Count

  • Second_Count: Index > First_Count AndAlso Index <=Second_Count

  • Third_Count: basically just an else branch or you can add else if with Index > (First_Count+Second_Count) AndAlso Index <= Third_Count

As you can see, I have filled all the conditions for else if branch i am still getting an error condition is required.

we can make use of different Options to split the data table within different parts e.g. in advance

This seems like a rather weird error you are encountering. If you add the Else If again, branch by branch, does it still happen?
For example, add the else if with the initial condition and see if the error disappeared, if yes, add the next branch condition and so on.

with some exploits we can model such a custom split in a compact way like:

Variables & Flow:

Details:

skipCount =
arrSplitConfig.Take(idx).Sum()
TableList =
TableList.Append(dtData.AsEnumerable.Skip(skipCount).Take(takeCount).CopyToDataTable).toList

Then loop over the resulting TableList and process each Segment within the iteration

For further Inspections / Tracings use the different debugging panels and go through the basic logics

Find starter Help here:
ppr_SplitDT_bySegmentLengthConfig.xaml (12.3 KB)