Iterate through datatable dynamically

Hi,

I have a requirement where I have to iterate in excel more times than actual rows are present. DtQuery.xlsx (9.8 KB) . So, Normally if we iterate through excel, it will iterate exactly the number of rows which are present. but as I have to iterate dynamically it will be more than the number of rows present. It’s count will be sum of L and M columns in attached excel. I have taken the count of both the columns and added them. But not getting any idea how to use that for iteration. Please help. Thanks!

So you will filter before and remove all rows that are empty in cols L or M.

Thank you for your reply.

I tried that but still, when I try to take the count of datatable it is giving the count of the column with the least rows as count of datatable.

@shubhamg830
can you requirement be understood in that way:

  • iterate over each row
  • repeat an action for the current looped X times (and X is dynamic / specific for each row)

yes, that’s right. The X times will be the sum of the count of L and M columns in the above attached excel.

@shubhamg830
find a protoype here:
Demo Data:
grafik

Flow:

Log:
grafik

find starter help here:
LoopDR_RepeatDynamic_ActionForDR.xaml (8.2 KB)

Thank you very much for helping me out. The requirement is slightly different.Capture . In the attached datatable screenshot, there are two columns and we have to iterate depending on the number of cells in it. Here, it will iterate 6 times as we have “A”, “B”, “C”, “3”, “5”, “2” as values in these columns. If we only had “A”, “B”, “C”, “3”, “5”, than it would iterate 5 times. Can you please help me with that. Thanks.

Sure we will help you

I did not understand the example

The prototype was created with the intention to show case some buildings block doing iterations
May we ask you on following:

  • add a second DataColumn (as you had mentioned L,M col)
  • fill in some sample values
  • describe us expected behaviour like
    • row 0: do this calucation …, do that execution …

this will help us to finalizing and solving your case.
Thanks

Sure, Here is the screenshot from the excel.

. So Normally if i will use a for each row to iterate through this excel, it will run 3 times as there are 3 rows in the excel.

But in my requirement, I want it to run as sum of L and M columns, As in the attached screenshot, sum of count of both columns is 6, so it should run 6 times.
In 2nd screenshot

sum of count of L and M columns is 5, so the loop should run 5 times. Inside the loop there is some data entry which needs to be done on a website.
Sincere apologies if I am not able to articulate the issue well.

@shubhamg830
it looks like you want to count the values from a column, where the values are not null or empty:

Do it like this for L column:
grafik
dtData.AsEnumerable.Where(Function (x) Not ( isNothing(x(LColNameOrIndex)) OrElse String.IsNullOrWhiteSpace(x(LColNameOrIndex).toString.Trim))).Count

Simialr do it for M coll. Sumup the counts and use it in the
Enumerable.Range(0,MySummedUpCountInteger)

It’s working. Thank you for the help. Much appreciated.

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