Find Max value from datatable

Hi!
Is there a quick way to find maximum value from collumn?
Someting like datatable.select(collumName=“priceHistory”).Max or is there way to get it like this or do i need to go through every value and compare them?

Thanks in advance

2 Likes

dt.AsEnumerable().Max(Function(row) row(“colname”))

6 Likes

Should it just work like that if i assign this to some variable?
Is there really space between? should it need rownumber or name or something other than just change “colname” of this. Sorry and thanks for quick answer.

Assign to Object variable and just change the column name(colname)

1 Like

Is this done in a write line activity? I am trying to go through a CSV file that I got from Yahoo Finance for GOOG > historical data > download ( I did all this through a web recording using clicks and type into and then saved the CSV file) and find the highest value in a column and save the date that this value is for. I use a sequence and read csv activity, but am stuck from there. Should I use an assign activity and then a for each activity?

dt.AsEnumerable().Max(Function(row) row(“abc”)).ToString —> Should work in write line

1 Like

I am using a write text file, in order to save it to a new notepad file. it will write out the highest number, but says it is 9, when the highest number is actually 980.304007

I have : row(“Close”).ToString.AsEnumerable().Max

it seems as if it is not returning the full value
and I also need to return the date associated with the highest value. I have attached the csv file I am talking aboutGOOG_YahooFinance_Data.xml (12.4 KB)

Hi again. Couldn’t get it work. I tried also put it in string and tried to buit it in object but it says object must be of type Double and it gives argument exception. What i do wrong?

Hey vvaidya. I saw your answer and it worked perfect for me. There is a similar solution to read the MAX number in a row? instead of a column.

In a row, if all values are integers, I think simple way is

row.ItemArray.Max

if not

row.ItemArray.Where(Function(s) IsNumeric(s)).Max.ToString

1 Like

Hi @andrejsantos,
To get max value from the column name
int maxVal = (int)table.Compute("Max(ColName)", "")
To get minimum value from the column

int minVal = (int)table.Compute("Min(ColName)", "")

Regards,
Arivu :slight_smile:

Hi @arivy86,

It doesn’t work for me. I receive a workflow exception.
Error:
"Main has thrown an exception | Source: Assign |
Message: Syntax error in aggregate argument: Expecting a single column argument with possible ‘Child’ qualifier.
Exception Type: SyntaxErrorException"bookmarkManager, Location resultLocation)

But i need to do this inside a for each row? If i have a table it’s possible to do something loke dt1.row.itemarray.max?

dt.AsEnumerable.Select(Function(s) s.ItemArray.Max.ToString).ToList

1 Like

Hi @andrejsantos,
get Max value from the data table column value
int MaxValue=Convert.ToInt32(dt.AsEnumerable().Max(Function(row) row("Column2")))

Regards,
Arivu :slight_smile:

5 Likes

HI @arivu96 @vvaidya

I want to grab entire row based on latest 6 greatest value under a column.Column values will be integer.Please Help!! Attached is the Excel sheet and column is hours based on greatest 6 hours i need to grab all that row and copy to a datatable please help!

Grab_latest 6 Hous and Entire Row.xlsx (11.7 KB)

1 Like

Hi @1vivek12,

Use Read range activity to get the datatable(dt).

Then use assign activity

Dt=dt.select("Hour > 6").CopyToDataTable()

Regards,
Arivu

1 Like

Hi arivu, @arivu96

Logic is like this if i have 23 24 25 26 27 28 29 30 32 32 33 34 35 36 37
under a column i need 6 greatest values rows. so o/p datatable should contains rows with hours values as
37 36 35 34 33 32 like this.

Ok @1vivek12, then refer this post
Re order data table and writting Excel (simple questions) - #4 by arivu96

Regards,
Arivu

hi please watch this video

1 Like