Working with the expression editor

You can enter the expression editor to add or edit an expression wherever you see the symbol 3 in the properties panel while editing a visualization. The 3 symbol indicates an expression field. Click 3 to enter the expression editor.

You can add expressions in two ways. Expressions can be created using the Fields, Functions, Variables, and Set expressions sections by making selections and inserting them into the expression field. You can edit the inserted expressions and add more complex expressions by typing directly into the expression field. You can undo an action by clicking the Undo button (B).

Inserting an expression using Fields

You can insert an expression by making selections from the Fields section at the right-hand side of the expression editor dialog.

Do the following:

  1. If you want to limit the available fields to those from a particular table in your data model, select a table from the Filter by table drop-down list.
  2. Select a field from the Field drop-down list.
  3. Select the aggregation function you want to use. The functions available are from the group of basic aggregation functions.
  4. If you want to insert the current selection as a set expression in your aggregation, use the Set expression check box. The current selection is always based on the default state.
  5. If you want to insert a Distinct or a Total clause together with the aggregation function, use the check boxes for each clause. Each clause can be used separately.
  6. Click Insert to insert the field and the function into the expression field.

    Tip: If you do not select an aggregation function, only the field will be inserted into the expression. Clauses can only be added if you select an aggregation function.
  7. Click Apply to close the Add expression dialog.

    For a dimension or measure, you continue by adding descriptive data for the dimension or measure.

Inserting a function using Functions

You can insert more than the basic aggregation functions by making selections from the Functions section at the right-hand side of the expression editor dialog.

  1. If you want to filter the list of available functions, select a function category from the Function category drop-down list.
  2. Select a function from the Function name drop-down list.

    You see a preview of the function.

  3. Click Insert to insert the function and the first parenthesis into the expression field.

  4. Type the rest of the expression in the expression editor according to the syntax.
  5. Click Apply to close the Add expression dialog.

    For a dimension or measure, you continue by adding descriptive data for the dimension or measure.

Inserting a variable using Variables

You can insert a variable by making selections from the Variables section at the right-hand side of the expression editor dialog.

  1. If you want system variables to appear in the list of available variables use the Show system variables check-box.
  2. Select a variable from the Variable drop-down list.

    You see a Definition and Value of the variable, if available.

  3. Click Insert to insert the variable into the expression field.

  4. Click Apply to close the Add expression dialog.

    For a dimension or measure, you continue by adding descriptive data for the dimension or measure.

Inserting a set expression using Set expressions

You can insert a set expression by making selections from the Set expressions section at the right-hand side of the expression editor dialog.

  1. Select whether to Use current selections or Use bookmark, as a set expression.

    You can only Use current selections if a selection has been made in the app. You can only Use bookmark if a bookmark is available. Use the Bookmark drop-down menu to choose between bookmarks.

  2. If you have defined alternate states, you can change the alternate state which the set expression is based on. Select the alternate state from Alternate state drop-down menu.
  3. Click Insert to insert the set expression into the expression field.

  4. Click Apply to close the Add expression dialog.

    For a dimension or measure, you continue by adding descriptive data for the dimension or measure.

Adding or editing an expression by typing

Do the following:

  1. Type the expression directly in the expression field.

    The field names you use in the expression are checked, and the syntax of the expression is validated.

    Tip: As you type in the expression editor, the expression is validated. If there is an error, you see a hint about what is incorrect. Additional error information may be available by clicking the icon next to the hint.

    When you type the name of a function in the expression, a tooltip appears that provides information to help you enter the function correctly, including argument names and qualifiers.

    Note: The tooltip for some chart functions shows the ALL qualifier. It is recommended that you do not use the ALL qualifier. Instead, use the set expression {1}.

    Each line in the expression editor is numbered and syntax highlighting is used.

  2. Click Apply to close the Add expression dialog.

    For a dimension or measure, you continue by adding descriptive data for the dimension or measure.

Auto-complete, evaluation and color coding

When typing in the expression editor, you get an auto-complete list of matching fields, variables and functions to select from. The list is narrowed down as you continue to type. The color coding helps you to see where fields, variables and functions are used in the expression.

The color coding applies both in the auto-complete list and in the expression itself.

You can verify that any dollar-sign expansions added in your expression give the correct result, by checking the expression evaluation, in the dollar-sign expansion preview.

How names are interpreted

It is not recommended to name a variable identically to a field or a function in Qlik Sense. But if you do, you must know how to use them in an expression.

Example:  

XXX is a field, a variable and a function. XXX will be interpreted as one of them depending on how you create the expression.

Examples of how names are interpreted
Expression XXX interpreted as
$(XXX) variable
Count(XXX) field
XXX() function

Rules for expressions

The following rules apply for chart expressions:

  • All expressions return a number and/or a string, whichever is appropriate.

  • Logical functions and operators return 0 for False, -1 for True. Number-to-string conversions and string-to-number conversions are implicit.

  • Logical operators and functions interpret 0 as False and all else as True.

  • Expressions that cannot be correctly evaluated, for example as a result of incorrect parameters or functions, return NULL.

Detailed syntax help

You can activate help mode by clicking the Help button (D). When active, all functions in the expression editor act like hyperlinks. Clicking on a function opens a browser tab to the online help section with the full description of how to use the specific function. When a function is clicked, help mode is exited.

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?