Find Max value from datatable

datatable

#1

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

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


#3

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.


#4

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


#5

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?


#6

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


#7

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)


Excel Automation task
#8

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?


#9

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.


#10

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


#11

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:


#12

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)


#13

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?


#14

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


#15

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:


#16

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)


#17

Hi @1vivek12,

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

Then use assign activity

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

Regards,
Arivu


#18

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.


#19

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

Regards,
Arivu


#20

hi please watch this video