# Bionic Rule Trend Calculation

The trend calculation function enables comparison of data between any two defined periods. This function is available with Bionic Rules Transformation Task, on clicking +Formula. An example use case is finding trends in usage metrics or support cases.

For more information on Formula Builder, refer to Formula Builder in Bionic Rules.

Trend Template (Non Percent):

The following list provides descriptions of all arguments in the Trend function:

• Period (inside the bracket): The period type such as days, weeks, months etc..
• Period Length: The length of the period.
• Source Field: The metric which is compared for the selected periods.
• Trend Indicator: The date identifier - this date is considered based on the Show fields (Date field) selected in the Transformation task for which trend is calculated.

Notes:

• Rule Run date is referred to identify the date record that qualifies as current period record.
• This is not the current date.
• Aggregation Method: The method used for aggregation such as average, sum etc..
• Prior Period: The number of earlier periods to be included for comparison.
• Adjust Missing Data: Set this to True for adjusting the missing data or False otherwise. Missing data is either absence of the record or a null value or empty value for the metric selected. When set to:
• True - the record for missing data is excluded by the Aggregation Method
• False - missing data or null value is considered as 0 (zero)

### Example

Consider the following sample setup with rule date - (1/9):

Trend(Period ( DAYS , 2 ), Clicks , Data Date , AVG , 3 , false )

Data Set

 Data Date (Current Date to Older) Clicks 1/8 1 1/7 0 1/6 5 1/5 3 1/4 8 1/3 null 1/1 6

Trend calculation for the provided data set.

Past 2 Days AVG minus Prior 6 Days AVG = Trend

Period Length 2 x Prior Period 3 = 6 Prior Days.

For Past 2 Days (1/8 - 1/7, as the rule run date is 1/9):

1 + 0       1

--------  = ----- = . 5

2           2

For Prior 6 Days (1/6 - 1/1):

5 + 3 + 8 + 0 + 0 + 6        22

---------------------------- = ------- = Approx. ~ 3.67

6                        6

As the record for 1/3 holds a null value and 1/2 is missing, 0 is considered instead. ​​​​​

Trend

.5 - 3.67 = -2.17

#### Alternative Options

The following examples use the same sample data used in the previous section:

• Use Trend Percent,  (( Trend / Prior Period ) *100) (In this example, it’s prior 6 days)

-2.17 / 3.67 = -.5913 * 100 = - 59.13%

• Set 'Adjust Missing Data' to “True”:

For Past 2 Days (1/8 - 1/7):

1 + 0       1

--------  = ----- = . 5

2           2

For Prior 6 Days (1/6 - 1/1):

5 + 3 + 8 + 6               22

---------------------------- = ------- =  5.5

4                        4

As Adjust Missing Data is set to 'True' and the record for 1/3 holds a null value and 1/2 is missing, this record is excluded from Trend calculation.

Trend = .5 - 5.5 = -5.0

Trend Percent = (-5.0 / 5.5) * 100 = -90.9%