# Find the best Km/Price car in a Datatable

Hello!

I have this Datatable:

audi ,a6 ,200000,55000,EUR
audi ,a6,150000,142000,EUR
audi ,a6,100000,42000,EUR
audi ,a6,98000,78000,EUR
audi ,a6,163000,30000,EUR
audi ,a6,210393,28000,EUR

What I’m trying to do is to find the lowest km car with the best price ( ‘audi ,a6,100000,42000,EUR’ should be the result )

How can I treat this, so I can find only the row I’m interested in?

Thank you!

Car Maker, Car Model, KM, Price, Currency
audi ,a6 ,200000,55000,EUR
audi ,a6,150000,142000,EUR
audi ,a6,100000,42000,EUR
audi ,a6,98000,78000,EUR
audi ,a6,163000,30000,EUR
audi ,a6,210393,28000,EUR

Hi @stoicescualflorin, welcome to the Community.

You can use the following approach to get the desired result:

→ Take a new data table ‘dtSorted’ & Clone the structure from the existing data table like this:

`dtSorted = yourCurrentDt.Clone()`

→ Take an Assign activity & assign this value:

``````dtSorted = (From row In dtCars.AsEnumerable()
Order By Convert.ToInt32(row("KM")), Convert.ToDouble(row("Price"))
Select row).CopyToDataTable
``````

→ Now you can see the lowest km car with the best price will be the first row of the sorted datatable. You can access the data of this row like this:

`dtSorted.Rows(0)`

Hope this helps,
Best Regards.

1 Like

Hello @arjunshenoy !

Unfortunately, this LINQ retrieves me the lowest KM car, but not the best km-price car ( it retrieves ‘audi ,a6,98000,78000,EUR’ and not ‘audi ,a6,100000,42000,EUR’

Thank you,

@stoicescualflorin

If the best is decided by adding both then try this

`dt.AsEnumerable.OrderBy(function(x) CDBL(x("KM"))+CDBL(x("Price"))).CopyToDatatable`

cheers

1 Like

Worked! Thank you so much!

1 Like

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