All Collections
Creating a Model
Creating and using variables in the Queries Editor
Creating and using variables in the Queries Editor
Ori Sagi avatar
Written by Ori Sagi
Updated this week

When creating a predictive flow in Pecan, you'll write SQL queries that transform your data into an AI-ready dataset. This enables a predictive model to be trained on your data, and enables new records to be fed into the model on an ongoing basis.

To ease the query-creation process, you can use preset variables or create new ones within the Queries Editor.

What is a variable?

In Pecan, a variable is a customizable property that can be injected into an SQL query. Variables contain unique information that affect how your query operates and the data your model is trained (and eventually makes predictions) on.

Variables help formulate your predictive question. They impact how a query functions, and help define model parameters like what you’re trying to predict, for whom, for what period, and with frequency. Each variable is assigned a string or numerical value.

Since they can be reused multiple times within multiple queries, variables allow you to work faster and more efficiently. They also make it easy for colleagues who don’t know SQL to update the premise of a query; all they have to do is duplicate your work and adjust the variables.

Pecan provides preset variables for a number of templates, and you can also create custom variables based on your unique needs or use-case. For a full list of these variables, see below.

How do you use a variable?

When creating a predictive flow in Pecan, you can use the preset variables provided in your template. Here’s how:

  1. From the “Connections” tab, click + New predictive flow and select the template you want to use. This will open the Queries Editor.

    In the right-side panel, you’ll see a panel named “Model Variables”:

    You can understand each variable by reading its tooltip and checking how the variable is being used in the queries that have been provided by default. (Note: if creating a predictive flow from scratch, you won’t see any default queries or preset variables.) You can also read about each variable in the below table.

  2. Define the value of each variable or use the default value that’s been provided.

    To define a variable - next to its name, indicate the appropriate string or value to populate the variable with. This will define certain key parameters for your model.

  3. When starting from a template, you’ll find that preset variables have already been injected into the queries. But here’s how to use a variable in a new place or way…

    To use a model variable:

    • Click anywhere within a query and type “{{“.

    • Then type the name of the variable.

      Here’s an example of how this would look for a variable named “frequency”:

  4. Once you’ve completed the above, the variable automatically becomes a part of the query – and its content will affect how the query operates. To see the value of each variable embedded within the query, click the “Compiled” tab at the top of the Editor.

    The below image illustrates how variables appear in the editable view and the compiled view:

    Note that although you can use variables before they’ve been defined, they’ll have no value in the compiled view, or have any impact when the query is actually run.

What variables are available and what do they mean?

Below are the preset variables that are currently available in Pecan templates:



Type of variable

Relevant template(s)


Define how frequently you want to generate a prediction for each customer.


Retention, Churn, Upsell, Engagement Decrease


Define how long after an activity a customer is considered to be “active”. This helps Pecan identify whom to make predictions for.


Retention, Churn, Upsell


Define how far beyond each marker date to make a prediction for.




Define a time period prior to the marker date during which a customer may have performed a number of activities. This helps Pecan identify whom to make predictions for.


Engagement Decrease


Define the desired number of days between a customer’s first activity and the prediction. Activity during this period will provide a basis for the prediction.


Conversion, LTV, HVC


Define the threshold (percentile) at which an entity is considered a High Value Customer.




Define the number of activities or transactions that may have been performed by an entity during their active period.


Engagement Decrease


Define the percentage decrease of activities or transactions that may have occurred for an entity during their prediction window (compared to their active period).


Engagement Decrease


Select the table that contains customer transactions. It will be used to define customers as active and identify their first activity.




Select the table that indicates whether each customer performed an upsell activity.




Select the table that indicates whether each customer had a change in status.



How do you create a new variable?

When creating a predictive flow, you may seee value in creating new variables –particularly if you’re building a use-case that goes beyond the provided templates.

For example, you may create a new model variable in order to formulate a a unique predictive question, or create a table variable in order to query specific sets of data.

To create a model variable:

  1. Click anywhere within a query, type “#{{“, and then type the name of your desired variable.

  2. The new name will appear under “Model Variables” on the right side of the screen. Click + Add variable.

  3. Next, In the blank field that appears, enter the string or value you want to assign to this variable.

  4. Click Save and your variable will now be saved and ready for use.

Did this answer your question?