Help with MAX() expression

Hello guys, does somebody help me with this MAX() expression? I have an ID column which has values with the word โ€œGTWโ€ plus an incremental number (GTW001,GTW153,GTW546) and I want to return the maximum value of that column without the expression โ€œGTWโ€ of course. Iโ€™m using SPLIT() and INDEX() to get the numeric part of the expression but Iโ€™m receiving an error by using MAX().

MAX(INDEX(SPLIT(GTW[ID GTW],โ€œWโ€),2))

โ€œMAX function is used incorrectlyโ€

0 5 115
5 REPLIES 5

Its because MAX() can only work with lists whereas INDEX() will always give a single answer.

This should work by wrapping it in a select function:

MAX(Select(
	INDEX(SPLIT(GTW[ID GTW],โ€œWโ€),2),
	TRUE
	)
)

Simon@1minManager.com

Aurelien
Google Developer Expert
Google Developer Expert

Hi @inaki_albisu

This wonโ€™t work, as MAX will want a list of numeric values.
You will need to create an intermediate virtual column.
INDEX(SPLIT([ID GTW],โ€œWโ€),2)

Then, the one you want:
MAX([ThisIntermediateColumn])

Edit:
I just noticed @1minManager answered at the same time.
@inaki_albisu you have the choice !

Edit2: @1minManager 's solution seems more relevant as it will require less calculation for your need !

Steve
Platinum 4
Platinum 4

My suggestion:

MAX(
  LIST(0)
  + SPLIT(
    SUBSTITUTE(
      CONCATENATE(GTW[ID GTW]),
      "GTW",
      ""
    ),
    " , "
  )
)
  1. GTW[ID GTW] gets the list of ID GTW column values.

  2. CONCATENATE(...) produces single a Text value from (1) (...).

  3. SUBSTITUTE(..., "GTW", "") removes all occurrences of GTW from (2) (...).

  4. SPLIT(..., " , ") produces a list from parts of the result of (3) (...).

  5. LIST(0) creates a list of type Number with one value, 0.

  6. LIST(0) + SPLIT(...) adds the results of (4) to the list of (5). Because (5) is a list of Number, the values added from (4) will be converted to Number.

  7. MAX(...) gets the maximum value from (6) (...).

See also:

Elegant and as usual very well explained @Steve

The @Steve effect.
3X_e_0_e06e4d7b554f826af6e368ce744c299749fdc7c5.gif

Top Labels in this Space