choose

Returns a value from a list based on a specified index in Salesforce Spiff. List values in Spiff aren't sorted by any default order. To make sure that you select the appropriate value, combine this function with sort() so that you sort the list values before you select a specific index.

Required Editions

Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience
Available in: Enterprise, Unlimited, and Developer Editions
Available for an additional cost in: Professional Edition with Web Services API Enabled

Syntax

choose(index_number, list)

Arguments

Argument Required? Description
index_number Required An integer that specifies the index value of the item in the list that you want to choose. The first item in the list has an index of 1, and the last item in the list has an index of -1.
list Required The items to choose from. The list can contain strings, numbers, records, or data filters, and can include identical entries. Enclose the list in brackets with comma-separated values. This list isn’t sorted by any default order.

Example

Choose the largest deal from a list of deals closed in a specific period, ClosedInPeriod. Sort the list by DealAmount in descending order, so that the list values go from largest deal amount to lowest. From the sorted list, select the first value, which represents the largest deal.

=choose(1, sort(ClosedInPeriod, DealAmount, -1))

If the list is empty, this function returns an error. To add check for an error, enclose the function in an iferror() function and show an error message.

=iferror(choose(1, sort(ClosedInPeriod, DealAmount, -1)), "Error message to show")

See Also