max_with_max

Finds a group of items that share the highest value for a specific attribute, and then returns the highest value of another attribute.

Syntax

max_with_max(RETURN-ATTRIBUTE, MAX-ATTRIBUTE)
Learn more about syntax for functions.

Parameters

  • RETURN-ATTRIBUTE: Any type of standard attribute or custom attribute (number, text, or other types). The function returns the highest value of this attribute for one of the selected items.
  • MAX-ATTRIBUTE: Any type of standard attribute or custom attribute (number, text, or other types), though typically you specify numeric or monetary attribute. The function selects all items that share the highest value of this attribute.

    If you specify a text attribute, the function sorts by lexicographic order and selects items at the end of the sort list.

Learn more about referring to inventory attributes.

Example

An ad group that's scoped to the "MyBrand" brand contains the following items:

BRAND TITLE PRICE DISCOUNT
MyBrand Red shoes $10.00 10%
MyBrand Yellow shoes $10.00 10%
MyBrand Blue shoes $10.00 5%
MyBrand Crew socks $5.00 20%
MyBrand Dress socks $5.00 20%
MyBrand Knee-high socks $5.00 15%

In an ad template, 
[to_string(max_with_max(DISCOUNT, PRICE))]

does the following:

  1. Scans the PRICE column and finds the items that share the highest price.
    In this case, the function selects "Red shoes", "Yellow shoes", and "Blue shoes" (which all specify a price of $10).
  2. Scans the DISCOUNT column for "Red shoes", "Yellow shoes", and "Blue shoes" and returns the highest value.

In this example, the function returns 10 ("Red shoes" and "Yellow shoes" both have a 10% discount).

Was this helpful?
How can we improve it?