Find The Max And Average Value From DataTable – In UiPath

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.

UiPath Find the max and average of datatable column 1UiPath Find the max and average of datatable column 2

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”)))

UiPath Find the max and average of datatable column 3.png

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”)))

UiPath Find the max and average of datatable column 4.png

Step 4:
Finally, let’s run the project.

Max Value:

UiPath Find the max and average of datatable column 5.PNG

 

 

 

 

Average Value:

UiPath Find the max and average of datatable column 6.PNG

 

 

 

 

Click here to download the Source Code…

Hope it has helped you… 

Advertisements

Author: Sharath Raju

Founder@www.ExcelCult.com

Leave a Reply