Recipe - How To Store Per-Calculation Values

Recipe - How To Store Per-Calculation Values


This article describes a recipe to store per-calculation values. Typically, you want to store a value a/ for a given calculation and b/ for a given user or team. For example, you could calculate each user's average credited revenue and store this. You can then re-use this value within different reward formulas, or perhaps simply show it to payees.

Storing Per-Calculation Values
You can store per-calculation values within:

You typically do NOT want to store per-calculation values formulas which are evaluated per-transaction. For example, if your plan is processing 1000 transactions, you probably do NOT want to calculate and store a per-calculation amount, because you will do so 1000 times.

For this reason, you probably should store per-calculation values within dynamic quota formulas. Using a dynamic quota formula, you can query the set to credited transactions, query for some value (ex: average revenue), and then store it within the calculation.

To store your value within the transaction, use the StoreCalculation(Name, Key, Value) function. Specify a name, a key, and the value to store. They key is often a credited user ID.

For example, you could specify a dynamic quota formula like this to store a value called "AverageRevenue" for each credited user:



Loading Per-Calculation Values
You can now load per-calculation stored values within:

To load values from your calculations, use the LoadCalculation(Name, Key) function.

For example, you can load each calculation's "AverageRevenue" value in a per-transaction reward formula:

 

For example, you can use the same convention to load each calculation's "AverageRevenue" value in a global reward formula:

  

Exporting Rewards
When exporting reward details from a calculation, calculated fields are automatically included in the export:


   
Displaying Stored Values
To display the calculated field on incentive dashboards, you need to specify an advanced option on your plan. The convention is PerformanceMetric=<Name> (ex: PerformanceMetric=AverageRevenue). This is equivalent to making a call to LoadCalculation(Name, Key) using a/ the specified name and b/ a key equal to the current dashboard user.