Average of a column without min and max

Hello guys,
I have a table stored on a variable and I want to obtain the average of the column without considering the min and max value, how can I do this?

Model Price
BMW 320 2690
BMW 320 10450
BMW 320 3750
BMW 320 6999
BMW 320 4950
BMW 320 2150
BMW 320 3400
BMW 320 6800
BMW 320 4700
BMW 320 4800

Thank you!

Hi @Ionut_Frincu

Try this

Dt.AsEnumerable().Average(Function(row) row.Field(Of Double)("Price")).ToString

Input:

image

Cheers!!

Hi @Ionut_Frincu

Could you confirm with that the above data stored in a String variable or in datatable variable.

If it stored in a datatable variable,

- Assign -> AverageValue = datatable.AsEnumerable().Average(Function(row) Convert.ToDouble(row("columnName"))).ToString()

Check the below workflow for better understanding,

Input -
image

Output to cross check in the excel with formula -
image

Hope it helps!!

@Ionut_Frincu

check it for reference

Hi @Ionut_Frincu

Use Assign Activity

DT.AsEnumerable().Average(Function(r) Convert.ToDouble(r(“ColumnName”))).ToString()

Note: Here Replace ColumnName to Price

Hope it will helps you :slight_smile:
Cheers!!

Assumption: Project is set to Windows Comaptibility

we recommend dividing it within two steps

Step 1: Price retrieval and ordering

Assign Activity:
arrAscPrices | DataType: Double Array =

dtData.AsEnumerable().Select(Function (x) CDbl(x("Price").toString.Trim)).OrderBy(Function (x) x).toArray

Step 2: AVG withouth Min/Max
Assign Activity:
avgPrice | Datatype: Double =
arrAscPrices.Skip(1).SkipLast(1).Average(Function (x) x)

Whenever adaptions is to do e.g. Double Conversions, Empty Value handling… we can incorporate as well. Also we can shift to Query Syntax

[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

Thank you @ppr for this solution, it is what I was looking for! :slight_smile:

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