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!
lrtetala
(Lakshman Reddy)
January 24, 2024, 10:23am
2
Hi @Ionut_Frincu
Try this
Dt.AsEnumerable().Average(Function(row) row.Field(Of Double)("Price")).ToString
Input:
Cheers!!
mkankatala
(Mahesh Kankatala)
January 24, 2024, 10:24am
3
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 -
Output to cross check in the excel with formula -
Hope it helps!!
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
Cheers!!
ppr
(Peter Preuss)
January 24, 2024, 10:44am
6
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!
system
(system)
Closed
January 27, 2024, 11:01am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.