How to Add the Data in Ascending order

I am using a For Each data table and using the assign activity where i am adding the data as per the condition in the end i have the variable called “lv_new” in which i am getting the data the loop will going to repeat as many times and we will get the value of lv_new but i don’t know how to sort that data and find out out the largest among them?

1 Like

Hey @anurita.mishra

You want to sort the data in lv_new or the datatable ?

Thanks
#nK

1 Like

Hey , In lv_new

1 Like

Hey @anurita.mishra

What is the datatype of lv_new please ?

Thanks
#nK

1 Like

Hey @Nithinkrishna
Lv_new is variable of type Integer in this i am getting the sum

1 Like

Hey @anurita.mishra

Sorry, It’s a bit unclear.

Actually I’m not getting what do you want to sort here please… ?

As integer variable is a constant Sum. Kindly explain.

Thanks
#nK

1 Like

Hey , @Nithinkrishna

I have a secenrio in which i have to sum the values corresponding to their ,material where materials are not fixed so i used a For Each Data where i am adding the weights of the materials and in the end. Suppose in the end i have the weights like For ex :- 34,65,78,9
Now i have to find out the Largest Among them.

Thanks,

1 Like

Hey @anurita.mishra

Cool, It’s clear now. Thank you for explaining.

Just have these in a List(Of integer) and let’s assume lv_new as integer list with weights

lv_new.Sort().Last

The above statement will help you get the largest.

Hope this helps

Thanks
#nK

1 Like

@anurita.mishra Just some additional info,

Creating & initialising a list from variables panel

List(Of Integer) lv_new = new List(Of Integer)

To add the weight on every iteration

lv_new.Add(weight)

Also, Add to collection activity can be used as an alternative for the above.

Thanks
#nK

1 Like

Hey @Nithinkrishna

This is not clear to me yet.

1 Like

Okay @anurita.mishra

You are getting some list of weights from the foreach iteration and from that you want to find the largest weight after the end of iteration…

Is this right,.please ?

Thanks
#nK

1 Like

Yes I am getting the list of weight
lv_new(of type int) = lv_new + CInt(dt_final.Rows(0)(“Weight”))

like this

but in lv_new each time the weight will be add and the previous one will be removed so first i have to store all the weight sums then i have to find out the largest among them hope its clear.

1 Like

Hey @anurita.mishra

You are on the right path…

And the Add which I mentioned is not sum or I’m not sure you are adding it for a different purpose.

You need to now please create a new integer list variable & keep on adding the weights to it on every iteration ( you can use Add to collection activity for adding)

After you add and the iteration completes, Just do the sorting mentioned above & you will get the largest of all the weights.

Hope this helps

Thanks
#nK

1 Like

Hey @anurita.mishra

You can also share workflow file if possible. So that I can provide you the flow.

Thanks
#nK

@anurita.mishra

use this:
here x is the input string,

x.OrderByDescending( Function(x) x)
output : { ‘9’, ‘9’, ‘7’, ‘6’, ‘6’, ‘5’, ‘5’, ‘3’, ‘3’, ‘2’, ‘2’, ‘2’ }

1 Like

dt.AsEnumerable().Max(Function(row) row(“rownametosort”))

You can use above linkq and get the max value, replace rownametosort with your DataTable column name.

1 Like

Hello @Nithinkrishna

I have few doubts are you available?

1 Like

Yes please say ?

Thanks
#nK

@anurita.mishra

Hi,
Your query is solved?

Yes @Vaibhav_Rajpoot_17