Finding Maximum Value,,,,,

Scenario:-
You have a list of dictionaries where each dictionary represents a product with a “Name” and “Price” field. How would you find the product with the highest price using LINQ in UiPath?

@ravisinghdas199,

Use this LINQ

maxPriceProduct = products.OrderByDescending(Function(product) Convert.ToDouble(product("Price"))).First()

Thanks,
Ashok :slight_smile:

@ravisinghdas199

highestPriceProduct = products.OrderByDescending(Function(p) Convert.ToDecimal(p("Price"))).First()

@ravisinghdas199

highestPriceProduct = products.OrderByDescending(Function(p) Convert.ToDecimal(p(“Price”))).First()

Cheers

1 Like

Hi @ravisinghdas199

Let’s say ProductPrice is the Dictonary of String, Object datatype variable.
HighestPricedProduct is the String variable which stores the Product which has high cost

Use the below linq expression in assign activity,

- Assign -> HighestPricedProduct = ProductPrice.OrderByDescending(Function(p) Convert.ToDouble(p("Price"))).First()("Name").ToString()

The above expression will get the Highest price product in the Dictionary variable.

Hope it helps!!

Check the below workflow for better understanding,

Result-

Hope it helps!!

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