Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
QlikSensor
Partner - Creator
Partner - Creator

Defining a temporary variable in the expression editor

Hi, sometimes expressions get really exhaustive. Is it possible for better readability to create a temporary variable which is only valid for this expression?

2 Replies
JordyWegman
Partner - Master
Partner - Master

Hi,

Yes this is possible. Do this in your script so that they don't get deleted.

Example:

let eSumSales = 'Sum(Sales)';

In chart:
$(eSumSales)

This will now evaluate your variable, Sum(Sales). Of course these can be a lot bigger than the example.

Jordy

Climber 

Work smarter, not harder
marcus_sommer

No, it's not possible. There is only one way to create a temporary (adhoc) variable with $(= ...) but they are executed once one the place where they are created and you could not reference on them.

Beside this you could use variables to store complete expressions and/or parts of them. Also you could use variables with parameter like: var: sum({< $1 = {$2}>} $3) and call them with: $(var(Field1, 'abc', Field2)). Further there are various possibilities to shorten expressions by replacing nested if-loops and similar constructs with pick(match()) or alt() or range-functions and probably some more.

Another possibility might occur in objects in which expressions are related to eachother. Here you could refer on them through the expression-label or the column-index like: column(1).

But the base of all this is a suitable datamodel. All or at least the most complex matchings and calculations which are not depending on selections should be flagged and/or (pre-)calculated. Everything left on this side will be require more or less efforts within the UI.

- Marcus