Take the second lowest price row in data table

Hello guys, I have a question. I have a data table that I extract, how can I find the second lowest price in the data table column and take certain info from that row? Thanks a lot :wink:

Hi @Povilas_Jonikas ,

Could you check with the below Expression, it should return the Second Lowest price row :

DT.AsEnumerable.OrderBy(Function(x)if(x("Price Column").ToString.IsNumeric,CDbl(x("Price Column").ToString),Double.MaxValue)).Skip(1).FirstOrDefault

Hi @Povilas_Jonikas

secondLowestPrice = dataTable.AsEnumerable()
    .Select(row => new
        Price = Convert.ToDouble(row["PriceColumn"]), // Replace "PriceColumn" with your actual column name.
        Info = row["InfoColumn"].ToString() // Replace "InfoColumn" with your actual column name.
    .OrderBy(item => item.Price)
    .Skip(1) // Skip the first (lowest) price.

Hope it helps!!

Hi @supermanPunch, will do, thanks a lot, but it should be used in which activity? Invoke code as i presume?

Use Sort Data Table to sort it in price order, then use yourDT.Rows(1) will get you the row with the second lowest price (ie the second row)

@Povilas_Jonikas ,

We can use this with Assign activity :

dr = DT.AsEnumerable.OrderBy(Function(x)if(x("Price Column").ToString.IsNumeric,CDbl(x("Price Column").ToString),Double.MaxValue)).Skip(1).FirstOrDefault

Here, dr is a variable of Type DataRow.

1 Like

Yeah, so i did it like this:

Then added activity add data row with DataRow set as dr, but got error Add Data Row: Object reference not set to an instance of an object.

What could be the problem? By the way, this is how the data table looks:
The price is in Kaina 2 column

her you would need a prepared DataTable which can store the datarow

e.g. dtNew = dtOrig.Clone

the dr.ItemArray | RowArray is to use when configuring the Add Data Row Activity

When, 1,70 should express a number with 7 and a Decimal part of 0,70 then the CDbl will handle it as 170 as the , is used as a thousand group seperator

Use 1.70 (dot) to be within the default definition or
Double.Parse(…, CultureInfo) method signature

Visualization (we assumed Lithuania)

When you can totaly rely on the DataTable Column DataType we also can avoid the Parsing by using x.Field(Of Double)(β€œKaina2”) instead of CDbl / Double.Parse


Thanks guys, I do believe that every aproach suggested was the correct one, but I went to a bit more simple approach after proccesing through every solution given. Thanks a lot

This is how I did it :smiley:

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