Skip to main content

Parameters in Scenarios

Updated over 9 months ago

Parameters are dynamic placeholders that allow you to customise the logic and thresholds of that particular scenario.

Instead of hardcoding values into your queries, parameters let you define variables that can be adjusted as needed for the scenario version you are working on.

This flexibility is crucial when certain thresholds, periods, or other values may need to be fine-tuned for different versions of the same scenario.

Defining Parameters

To define parameters in your scenario:

  1. Access the Parameters Section:

    • Begin by clicking on the edit icon (pencil) next to the "Parameters" section in the scenario editor. This allows you to create and manage parameters for the current scenario version.

  2. Define Parameters:

    • Click on "Add parameter" to start defining a new parameter.

    • For each parameter, you'll need to provide a:

      • Display Name: a user-friendly name for the parameter, such as "Person count" or "Value sum."

      • Parameter Name: This is the name you will use in the query, preceded by a dollar sign (e.g., $person_count, $value_sum). When defining parameters, the dollar sign is automatically included.

      • Type: Choose the type of the parameter:

        • Numeric: For thresholds, counts, or ratios (e.g., $person_count).

        • Period: For defining time periods (e.g., $period).

        • Array: For defining lists of strings (e.g. $payment_type).

    • You can add as many parameters as your query requires. Each parameter should correspond to a value in your query that you expect to change or adjust over time.

    • After defining all necessary parameters, click "Confirm" to finalise your parameter definitions.

  3. Define Parameter Values:

    • Once the parameters are confirmed, you can define their actual values. These values will be used when the scenario runs and will replace the parameter placeholders in your query.

  4. Using Parameters in Queries, Scenario Logic, and Details:

    • After setting the parameter values, you can start using these parameters in your Scenario Query, Scenario logic, and Details. Simply reference the parameter name (e.g., $person_count, $value_sum, $period) in the relevant sections, and the system will automatically substitute the parameter value.

      • When using array parameters, add any before the parameter name, e.g. any($payment_type). Array parameter values may only contain letters, digits and underscores. Currently, empty arrays are not allowed.

Using Parameters in Scenario query

When constructing a query for a scenario version, you replace static values with parameters, for example, replacing a number representing an amount to a parameter holding the amount value. This allows you to adjust the query by simply changing the parameter values, rather than editing the query itself.


Simple scenario example

Consider a scenario where you want to check if transaction's amount is 50,000 or higher:

An example query without parameters:

Extend to copy the query

SELECT amount >= 50000, amount
FROM transaction
WHERE id = $transactionId

The same query with a parameter:

Extend to copy the query

SELECT amount >= $amount, amount
FROM transaction
WHERE id = $transactionId

In this example, instead of hardcoding the amount (50000), we've used the parameter $amount. When you change the value of this parameter within the scenario version, the query will automatically use the updated value.


Complex scenario example

Consider a scenario where you want to check if a current transaction is sent to a recipient account that has received a total of 20,000 in the last 30 days from at least 20 other senders.

In simple terms, this scenario has three values it checks:

  1. The total sum of the incoming transactions.

  2. The total number of unique senders.

  3. The period when these transactions have taken place.

Let's say we have defined parameters for this scenario like this:

  • Total sum: $value_sum (Numeric)

  • Count of senders: $person_count (Numeric)

  • Period: $period (Period)

An example query without parameters:

Extend to copy the query

select
count(distinct person_id)>=20 and sum(value ) >=20000 ,
sum(value ), count(distinct person_id )
from (select receiver_account, timestamp from transaction where id = $transactionId and direction = 'OUTGOING'
) sub
join person_aggregate pa on pa.receiver = sub.receiver_account and pa.organisation_id = $organisationId
where pa.aggregate_date between sub.timestamp-'30 days'::interval and sub.timestamp
and pa.aggregate_type = 'TRANSACTION_TO_RECEIVER_ACCOUNT'
and aggregate_operation = 'SUM'

In simple terms, this scenario has 3 values it checks:

  • The total sum of the incoming transactions

  • The total number of unique senders

  • Period when these transaction have taken place

Let's say we have defined parameters for this scenario like this:

  • Total sum - $total_sum - Numeric

  • Count of senders - $count - Numeric

  • Period - $period - Period

Query With Parameters:

Extend to copy the query

select
count(distinct person_id)>=$count and sum(value ) >=$total_sum ,
sum(value ), count(distinct person_id )
from (select receiver_account, timestamp from transaction where id = $transactionId and direction = 'OUTGOING'
) sub
join person_aggregate pa on pa.receiver = sub.receiver_account and pa.organisation_id = $organisationId
where pa.aggregate_date between sub.timestamp-$period and sub.timestamp
and pa.aggregate_type = 'TRANSACTION_TO_RECEIVER_ACCOUNT'
and aggregate_operation = 'SUM'

Here, the parameters $person_count, $value_sum, and $period make the query dynamic and adaptable for the specific scenario version. By adjusting these parameters, you can fine-tune the scenario without needing to rewrite the query.

When using array parameters, add any before the parameter name, e.g. any($payment_type).


Using parameters in Scenario logic and Details

You can use these dynamic parameters in Scenario logic when describing how the scenario works, and in Details to define what is showed with each alert generated.

Simply type the Parameter name (e.g. $amount) when writing and the parameters will automatically be replaced with the values the parameter carries.


Example Scenario logic With Parameters:

When Parameters are defined with values, the Scenario logic is depicted as:

Did this answer your question?