Define Static Variables

This topic describes what you need to know to understand and define static variables for use in data filters and expressions.

About Static Variables

Use a static variable when you need a variable with a fixed value.

For example, suppose you want to create an expression to group times of day into different day segments. If Prime Time were one of those segments and corresponded to the hours between 5:00 PM and 10:00 PM, you could create a CASE statement like the following:

CASE WHEN "Hour" >= 17 AND "Hour" < 23 THEN 'Prime Time' WHEN... ELSE...END

Hour is a logical column, mapped to a timestamp physical column using the date-and-time Hour(<<timeExpr>>) function.

Instead of entering the numbers 17 and 23 into this expression as constants, you could create and use a static variable named prime_begin, set the variable's value to 17, and then create another variable named prime_end and set the variable's value to 23.

When you create a static variable, you must include a default value. You can set the Value field with a number, character, date, time, or timestamp value. Or you can use the Expression Editor to insert the Date, Time, and TimeStamp constants into an expression.

Create a Static Variable

Create a static variable when you need a variable with a value that doesn't change, for example, minimum credit score or preferred credit score.

After you define and save static global variables, they're available for you to add to the semantic model's data filters or expressions.

In a semantic model, you create and define a static variable within an initialization block. You can't create and define a standalone static variable and then later associate it with an initialization block.

A static variable must have a default value that is a numeric, character, date, time, or timestamp value. If you initialize a static variable using a character string, enclose the string in single quotes ( ' ). You can use the Expression Editor to insert the Date, Time, or Timestamp constants.
  1. On the Home page, click Navigator and then click Semantic Models.
  2. In the Semantic Models page, click a semantic model to open it.
  3. Click Variables.
  4. Click Create and then click Create Initialization Block.
  5. In Create Initialization Block, go to the Name field and enter an initialization block name.
  6. Go to the Type field and select Static. Click Add.
  7. Confirm that the Variables tab is displayed and then click Add Variable and enter a unique name.
  8. Go to the Value field and enter a static value. Or, click Detail View and click Open Expression Editor to create an expression that determines the static value.
  9. Click Save.