Unlock the full potential of your alerts with custom expressions!
With custom expressions, you can tailor triggers, filters, and alert content to match your exact needs. Using advanced options like OR conditions, if statements, and even visual emojis based on your data, you can create dynamic alerts that perfectly fit your workflows. You can also set custom date intervals and apply more advanced logic to your alerts.
Please note: this feature is available at the moment for SQL data sources.
In this article we are going to cover the following topics:
In this article we are going to cover the following topics:
Where Can You Add a Custom Expression
1. Trigger is data events
2. Trigger is metric over time
Examples and Use Cases
1. Custom Date Intervals
This feature allows you to define time-based conditions relative to your metric triggers. For instance, if you want to display the date of the previous week relative to a metric, simply subtract 7 days from the time axis field.
β
βExample: If a metric is triggered today and you want to reference the same metric from last week, use a custom expression to adjust the time by 7 days.
2. Comparing Two Data Points
Set conditions that compare different data points to trigger specific actions. This feature enables you to create dynamic rules based on time-based relationships or any other data fields.
β
βUse Case: If you want to identify inactive users, you can create an expression like last_active_ts > (last_purchase + 7)
. This checks if a userβs last activity was more than 7 days after their last purchase. If true, the user can be flagged as inactive for potential re-engagement.
β
β
3. Aggregation Calculations
Perform calculations based on data fields without needing to add them to the metric in advance. This option is useful for calculating ratios or other aggregate data metrics within your alerts.
β
βExample: You can create a custom expression to calculate the ratio between two data fields (e.g., sales versus returns) and trigger an alert if this ratio falls below a certain threshold.
4. Conditional Logic (If-Else Statements)
Using if-else logic, you can set up dynamic conditions within your alerts. This allows for different actions or classifications based on the specific values or flags in your data.
β
Use Case: This expression evaluates whether a customer is new or returning and adjusts the threshold for a "high-value" purchase accordingly:
For first-time customers: the purchase is considered "high-value" if the total price exceeds $100.
For returning customers: the threshold for a "high-value" purchase is set higher, at $200.β
5. OR Conditions
Use OR logic to trigger alerts when multiple alternative conditions are met.
Expression: total_price > 300 OR purchase_count > 5
βUse Case:
This expression helps detect if a customer makes a purchase over $300 or has made more than 5 purchases. It helps you identify either high-value purchases or loyal, frequent buyers. This is useful when you want to classify important customers using different criteria.
6. Using Dynamic Context Values: Current Date and Time
You can use dynamic context values in your custom expressions to make them more adaptable and responsive to real-time data. These values allow you to compare events or metrics relative to the current date or the current date and time.
Option 1: Current Date
TheCurrent Date
value refers to todayβs date without including the time component. Use this option when you need to create expressions based on full days.Use Case: identify inactive accounts for more than 30 days relative to the current date.
Expression Example:
last_active_date < (Current Date - 30 days)
Option 2: Current Date and Time
TheCurrent Date and Time
value includes both the current date and time, making it useful for more precise conditions where time down to the hour is important.Use Case: Monitor events that occur within the last 24 hours using the current date and time.
Expression Example:
event_timestamp > (Current Date and Time - 24 hours)
These dynamic context values allow you to create rolling conditions that adjust automatically, so you don't need to manually update static dates or times in your expression logic.
Useful syntax to build an expression
Logic operators
You can use natural language - and / or operators
Example: net_revenue >1000 or is_first_purchase
Date intervals
Use "-" or "+" and a date unit (i.e. days / months / years)
Example: datetime_field - 7 days
Working with strings
To add a string value you'll need to use the double quates sign "
Example: "this is a string value"
Using Context Values (Current Date and Time)
To use the current date or current date and time dynamically, include the following keywords in your expressions:
Example:
last_active_date < (Current Date - 30 days)
Example:
event_timestamp > (Current Date and Time - 24 hours)
Start With a Template
Templates can be accessed by clicking "Start with a template" located on top right part of the expression builder modal.
Show thumbs up or down emoji based on a value
Use this template to build a conditional logic expression that evaluates to either true or false.
The output will be: A thumbs-up emoji (π) if the value is positive and a thumbs-down emoji (π) if the value is negative.
For example:
Dynamically display an emoji relative to the data, according to your defined logic. If the price is higher than the discounted amount (a positive indicator) display π, else display π.