Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Mutant Variable

Hi everybody

I need to find a way to make a variable changes depending of the object in which this is deployed,

The problem is that I need to use the same variable for different objects but these have different dimensions

for example:

if( $(vObjectID)=1, // or something like this

  sum(total {$<FLAGP={1},  >}SALDO) ,

 

sum(total <AnioMes> SALDO)  )

Best Regards

4 Replies
Anonymous
Not applicable
Author

You need to 2 variables.

If just set expression is changing the following should do:

sum(total $(var1)SALDO)

sum(total $(var2)SALDO)

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Any specific reason why you cannot have customized expressions in different objects?

Not applicable
Author

The expession is into a variable in script and this is chained  many times with many others variables:

Let vSaldo =

if( $(vObjectID)=1, // or something like this

  sum(total {$<FLAGP={1},  >}SALDO) ,

sum(total <AnioMes> SALDO)  );

Let vTotal = $(vSaldo) + $(vOtherVariables);

Peter_Cammaert
Partner - Champion III
Partner - Champion III

IMHO this is a different problem. I read the first one as: "is there a method to get the object ID in an expression so that it can be adjusted according to the object where it is used". Don't know the answer to that. There is an (undocumented) function called GetActiveSheetId, maybe there is also one that returns the active object ID.

The second question is about how to store expressions into variables for later use. You can do that like this:

LET vSaldo = '=IF ($' & '(vObjectID) = 1, sum(total {$<FLAGP={1},  >}SALDO) , sum(total <AnioMes> SALDO)  );';

If you want to manipulate the content of this variable later on, you have to make sure that $-substitution is NOT performed on variable $(vObjectID) in the script already. Otherwise your expression becomes broken.

A solution for that is to use another character instead of the dollar sign, and replace the replacement character during the very last assignment, e.g.

LET vSaldo = '=IF (§(vObjectID) = 1, sum(total {$<FLAGP={1},  >}SALDO) , sum(total <AnioMes> SALDO)  );';

LET vSaldo2 = '$(vSaldo)' & ' + 1000';

LET vTotal = Replace('$(vSaldo2)', '§', '$'); // No script manipulations anymore after this statement.

Best,

Peter