Find Maximum and Minimum Value from DataTable in UiPath
Hi Welcome to another post of Codehunters.
In this short tutorial we will see how we can find the maximum and minimum value from a datatable in UiPath with just a single line of code.
I have an excel sheet with a Column Age, I want to find the Maximum and Minimum age from this column.
Launch UiPath Studio Now and create a Blank process. The first thing we need to do is to read the Excel file and load the data into Datatable.
Sol lets drag and drop Read Range activity I will use the Workbook Excel Activity. Now give the Excel File Path and the Sheet name as Sheet1 and we will read the complete Range so it will be Blank, your read range activity should look like below.
We will hold the data in a Datatable Variable lets call it dtExcelData. Create a new variable called dtExcelData and in the output property provide the name of the variable. Now we have the Excel Data in the DataTable.
We now need to find the Max and Min Value so Drag two Assign Activity One for maximum and One for Minimum. And create two variable of Integer type. We will call first variable as MaxSalary and the datatype as Integer we will create another variable called MinSalary and set the datatype as Integer for this as well. Here is the screenshot of Variable panel.
Now in the assign activity we take the MaxSalary on the Left hand sid and on right hand side lets type the code to find the Max Salary so the code is
dtExcelData.AsEnumerable.Max(Function(row)CInt( row("Salary")))
In the same way we will type the MinSalary in this assign activity and we will copy the same code from Max and will just change the Max Function to Min Function.
Now we are done, to show the output let’s drag a MessageBox and type MaxSalary is +MaxSalary and Min Salary is + MinSlary
The process should look like this screenshot
Now we can run the process. And here we can see the max and Min salary is displayed in the message Box. we can also validate the same from the excel sheet.
So this is how you can find Max and Min Value from a datatable easily in UiPath.
You can watch the video tutorial below.
Hope this helps and I will see you in the next post. Till then Code with Confidence.