Assuming we have a data set and we have been asked to calculate the max and average of a particular column.
How do we do it?
Let us see how to do it using LINQ !!!
MAX Value:
myMax_Value = dt_Sample.AsEnumerable().Max(Function(row) cint(row(“ColumnName”)))AVERAGE Value:
myAverageValue = dt_Sample.AsEnumerable().Average(Function(row) cint(row(“ColumnName”)))Note:
1.Replace dt_Sample with your DataTable
2.Replace ColumnName with your required column name
Example
Implementation using UiPath :
Let us implement a workflow which takes a sample DataTable and displays the Max and Average of a particular column of that DataTable
Step 1:
Drag “Build Data Table” activity into the design panel and populate it with some sample data.
Step 2:
Drag “Message Box” activity into the design panel to display the Max value of Sales Column and populate it with the below code.
dt_Sample.AsEnumerable().Max(Function(row) cint(row(“Sales”)))
Step 3:
Drag “Message Box” activity into the design panel to display the Average value of Sales column and populate it with the below code.
dt_Sample.AsEnumerable().Average(Function(row) cint(row(“Sales”)))
Step 4:
Finally, let’s run the project.
Max Value:
Average Value:
Click here to download the Source Code…
Hope it has helped you…
If the rows contains some blanks along with numbers then it does not work. Any idea how to fix
Yeah Kapil, in that case we have to first remove duplicates and then apply this query 🙂
Hola lo use con CDate pero me toma solo fechas MM/DD/aaaa, y necesito DD/MM/aaaa
Hi Felipe, I actually understand only English language ?
how to find the total and average of 3 students marks