Vai al contenuto principale

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.

Procedere come indicato di seguito:

  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.

    Suggerimento: 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. Fare clic su Applica per chiudere la finestra di dialogo Aggiungi espressione.

    Per una dimensione o una misura, continuare aggiungendo dati descrittivi per la dimensione o la misura.

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. Fare clic su Applica per chiudere la finestra di dialogo Aggiungi espressione.

    Per una dimensione o una misura, continuare aggiungendo dati descrittivi per la dimensione o la misura.

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. Fare clic su Applica per chiudere la finestra di dialogo Aggiungi espressione.

    Per una dimensione o una misura, continuare aggiungendo dati descrittivi per la dimensione o la misura.

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. Fare clic su Applica per chiudere la finestra di dialogo Aggiungi espressione.

    Per una dimensione o una misura, continuare aggiungendo dati descrittivi per la dimensione o la misura.

Adding or editing an expression by typing

Procedere come indicato di seguito:

  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.

    Suggerimento: 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.

    Quando si digita il nome di una funzione nell'espressione, viene visualizzata una descrizione comandi contenente informazioni che facilitano la corretta immissione della funzione, compresi i nomi e i qualificatori degli argomenti.

    Nota: La descrizione comandi di alcune funzioni grafiche mostra il qualificatore ALL. Si consiglia di non utilizzare il qualificatore ALL. Utilizzare invece l'espressione di gruppo {1}.

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

  2. Fare clic su Applica per chiudere la finestra di dialogo Aggiungi espressione.

    Per una dimensione o una misura, continuare aggiungendo dati descrittivi per la dimensione o la misura.

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

Si sconsiglia di denominare una variabile con lo stesso nome utilizzato per un campo o una funzione in Qlik Sense. Tuttavia, in caso affermativo, è necessario sapere come utilizzarli in un'espressione.

Example:  

XXX è un campo, una variabile e una funzione. XXX verrà interpretato come uno di essi a seconda di come l'espressione viene creata.

Esempi di come vengono interpretati i nomi
Espressione XXX viene interpretato come
$(XXX) variabile
Count(XXX) campo
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.