How to add ordinal numbers after a condition?

Hi Folks,
I would like to insert ordered values ​​in a datatable after condition, for example.
I have a column in which one of the lines is empty or zero, I would like to add the value in this column and add sequential values ​​in the following lines.
Column “Prioridade” are actual values.
I would like something similar to “Corret - AFTER”

To fill in the zero values ​​I managed to do with LINQ, I only need the next ordered values.

While:
Convert.ToInt32(row1(“Prioridade”))= 0 OR (Convert.ToInt32(row1(“Prioridade”)) > UltimoRange OR Convert.ToInt32(row1(“Prioridade”)) < Count)

Assign:
PrioridadeAnterior = in_Criticidade.Rows(in_Criticidade.Rows.IndexOf(row1)-1)(“Prioridade”).ToString
row1(“Prioridade”) = convert.ToInt32(PrioridadeAnteriorLinha)+1

And I would like,
I would like to add values ​​on all the following lines in the sequence, I think it would look something like this:
ProximaPrioridade = in_Criticidade.Rows(in_Criticidade.Rows.IndexOf(row1)+1)(“Prioridade”).ToString

I made a solution that ordered all rows in the table, I would like to order only from zero onwards.

UiPath
image

@Michi2021 What if the Column contains multiple 0’s, how would you like to go on updating the values Sequentially ?

Thanks for answering.
I would like to consider the first zero, and reorder until the end of the datatable.

@Michi2021 Can you tell us why have you used Linq ? or what operation does the Linq query do ?

LINQ was the best option for me to take the value of the previous line and add it with 1 more.

“PrioridadeAnterior = in_Criticidade.Rows(in_Criticidade.Rows.IndexOf(row1)-1)(“Prioridade”).ToString
row1(“Prioridade”) = convert.ToInt32(PrioridadeAnteriorLinha)+1”

@Michi2021 Check this Workflow :

I have used two methods to achieve your expected output. The Second method which I have commented is not so good if there are more records to be updated. Use only any one method. The other method should be commented. I have done it using a Sample Excel Sheet. Check the Input Sheet. Execute the Workflow. An output sheet should have been generated in the same excel. Check the Input and the Output and see if it is the right output you needed.
UpdateColumnValues.zip (9.1 KB)

1 Like

That’s exactly what I needed.
Thank you so much.

1 Like

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