Syntax

MAXROW(table-name, column-name[, select-row?])

Arguments

  • table-name (table name): the name of the table to search as a literal Text value (quoted or unquoted); may not be an expression.
  • column-name (column name): the name of the column of the named table in which to find the maximum value, as a literal Text value (quoted or unquoted); may not be an expression.
  • select-row? (Yes/No expression): an optional expression, evaluated for each row of the table, that returns TRUE or FALSE indicating whether the row should be included (TRUE) or excluded (FALSE) in the search for the maximum value. If no expression is provided, all rows of the table will be searched (equivalent to the expression, TRUE).

Return Value

Ref: The key of a row in the table that contains the maximum value found in the named column from among the rows selected by the select-row? expression, or from among all rows if select-rows? was not provided.

If the column maximum was found in more than one row, one of the maximum rows will be chosen at random.

Examples

MAXROW("Products", "Discount") : returns the key value for the row in the Products table that has the highest value in the Discount column (i.e., which product has the greatest discount?). Equivalent to MAXROW("Products", "Discount", TRUE).

MAXROW("MyTable", "_ROWNUMBER") : returns the key value for the row in the MyTable table that has the highest value in the _ROWNUMBER column (i.e., which row was added last?).

MAXROW("Students", "GPA", ([Class] = "2018")) : returns the row for the (one) student with the highest GPA of the class of 2018.

MAXROW("Sales", "Close Date", ([City] = "Madrid")) : returns the row for the newest sale in Madrid.

MAXROW("Events", "Date", ([Date] < [_THISROW].[Date])) : returns the row for the most recent preceding event.

MAXROW("Events", "Date", ([Date] < DATE("1/1/" & YEAR(TODAY())))) : returns the row for the most recent event prior to this year. See also: DATE(), TODAY(), YEAR().

MAXROW("MyTable", "SomeColumn", FALSE) : returns a blank value because the select-row? expression will always return FALSE, excluding all rows from the search.

Common Problems

MAXROW(MyTable, Date) produces the error, Expression [...] could not be parsed due to exception: #VALUE!. In this example, the column name, Date, has significance within the internals of AppSheet and causes confusion. Any table name that matches an AppSheet or Excel function name may produce this problem. To fix, quote the problem name: MAXROW(MyTable, "Date")

MAXROW("Events", "Date", ([Venue] = [Wanted Venue])) produces the error, Unable to find column [...]. Column references within the select-row? expression (e.g., [Venue]) are to the row being considered as the table is searched. To access columns outside the row being considered, such as when using MAXROW() from within a column constraint, app formula, initial value, or format rule, reference the external column using _THISROW: MAXROW("Events", "Date", ([Venue] = [_THISROW].[Wanted Venue])) 

See Also

FILTER(), MAX(), MINROW(), ORDERBY(), SELECT()

Did this answer your question?