# DRAFT Price formula reference

When you create a product rate plan charge with the Multi-Attribute Pricing charge model, you have to specify a price formula for the Price Formula field.

A price formula can consist of functions that are used to calculate the actual rating amount for each usage record. Mathematical operations ( +, -, /, * ) are also supported in price formulas. Parentheses can be used to emphasize precedence.

### Functions used in price formulas

The following table lists the functions that can be used in price formulas.

Function Description Notes Examples
fieldLookup("<object>", "<field>") Returns the value of a field on a standard Zuora object. Currently, only the “usage” object is supported.

Examples:

`fieldLookup("usage", "multiplier__c")`

max(<argument1>, <argument2>, … ) Returns the greatest numerical value of the arguments.

Arguments must be a numeric value, or a function that returns a numerical value.

This function supports two or more arguments.

Examples:

• `max(1, 2, 3.4)`
This example returns 3.4.

• `max(100.23, usageQuantity()) `
This example returns the greater value of the quantity on the current usage record, or 100.23.

• `2 * max(0, (usageQuantity() - 50))`
This example returns zero if the usage quantity is no more than 50 usage records.
min(<argument1>, <argument2>, … ) Return the smallest numerical value of the arguments.

Arguments must be a numeric value, or a function that returns a numerical value.

This function supports two or more arguments

Examples:

• `min(10, 9, 8, 7, 6, 5, 4)`
This example returns 4.
objectLookup("<customObject>", "<targetField>”, [ “<field>”=<value>, ...] )

Returns the <targetField> of the specified <customObject>, performing the lookup by using all the provided <field>=<value> criteria.

<value> is any supported string, number, or function.

It is best practice not to nest objectLookup() functions within each other.

Currently, the criteria must uniquely identify one row in the custom object. You can specify as many criteria as necessary, using a comma to separate the field/value pairs.

Examples:

`objectLookup(“myObject”, “level__c”, [`

```  “color__c” = “red”,   “type__c” = 12,   “sublevel__c” = fieldLookup(“usage”,“my_level__c”) ])```

usageQuantity(<argument>) Returns the quantity for the usage record. This function can contain an optional argument.
• <none>: Returns the quantity on the current usage record being evaluated.
• RUNNING: Returns the sum of the quantity for the usage records already evaluated.  The running total is exclusive of the current usage record.
• TOTAL: Returns the sum of the quantities for the usage records already evaluated plus the current usage record being evaluated.
This function might be useful with certain types of limit scenarios, for example, charging a per-unit charge with a maximum of 100 units. Examples:
• `1.5 * usageQuantity()`
• `min(100, usageQuantity(RUNNING)+usageQuantity()`
• `min(100, usageQuantity(TOTAL))`

effectiveDate(<objectLookup>, "<effectiveDateField>")

effectiveDate(<objectLookup>, "<effectiveDateField>", <effectiveDate>)

Adds effective date semantics to the provided <objectLookup> function.

This function is intended for use in custom object lookups where you provide the name of an additional field on the custom object (<effectiveDateField>). The `effectiveDateField` field contains a date value, for example, 2019-01-23, that indicates when the data for that record becomes active.

The record with a date closest, but earlier than or equal to the effective date value is used.
The first form will use the start date of the usage record (converted to a day) to compare with the <effectiveDateField>.

The second form allows the use of a value or function that returns a date or string (yyyy-mm-dd) and uses that instead of the start date in the comparison.

Examples:

• `effectiveDate(objectLookup("pricecatalog__c",``"output__c", ["field1__c"="gold status"]),``"catalog_date__c" )`

This example uses the start date of the usage to find the appropriate row.

• `effectiveDate(objectLookup("pricecatalog__c", ``"output__c", ["field1__c"="gold status"]),``"catalog_date__c", '2019-06-20' ) `

This example ignores the start date of the usage to rate, and all usage for this subscription uses pricing as of June 20, 2019 in the custom object.

firstValue(<argument1>, <argument2>, …) Returns the first non-null value from the arguments. Arguments might be any supported function.
This function supports 2 or more arguments.

Examples:

• `usageQuantity() * firstValue(objectLookup("myCarObj", "outputField__c",  ["maker" = fieldLookup("usage", "maker__c"), "style" = fieldLookup("usage", "style__c")]),              objectLookup("myRegionObj", "outputField__c", ["region" = fieldLookup("usage","region__c")]), 0.10)  `

This example first attempts a lookup of the maker and style, then a lookup of the region, and finally falls back to a hard-coded default value of 0.10.

• `firstValue( fieldLookup("usage", ``"preratedAmount__c"), 20.50)  `

This example returns the default value of 20.50 if the usage record does not have a defined prerated amount.