Skip to main content
Announcements
Save $600 on Qlik Connect registration! Sign up by Dec. 6 to get an extra $100 off with code CYBERSAVE: REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
rutger_jansen
Contributor III
Contributor III

Variable with parameter

Hi,

I have several calculations that I want to put into variables and they would need to accept a variable as a parameter.

E.g., I have a calculation as:

SUM( {< $(vLatestMonth), FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< $(vLatestMonth), FLAG = {'Y'} >} AMOUNT_2 )

/

SUM( {< $(vPrevMonth),   FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< $(vPrevMonth),   FLAG = {'Y'} >} AMOUNT_2 )

And I want to define a variable for that calculation:

vMetric(@)= SUM( {< @, FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< @,   FLAG = {'Y'} >} AMOUNT_2 )

And then use the variable in a chart by passing in another variable containing some set analysis:

$(vMetric (vLatestMonth) ) / $(vMetric( vPrevMonth ) )


If that is possible, what is the correct syntax?


Thanks,

Rutger

1 Solution

Accepted Solutions
marcus_sommer

It looked quite ok. unless some small syntax-issues and should work if your vLatest/PrevMonth variables contain a valid set analysis statement - and that there is no comma included which is always regarded as a parameter-delimiter. Therefore try this:

vMetric:

SUM( {< $1, FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< $1,   FLAG = {'Y'} >} AMOUNT_2 )

$(vMetric (vLatestMonth)) / $(vMetric(vPrevMonth))

- Marcus

View solution in original post

6 Replies
marcus_sommer

It looked quite ok. unless some small syntax-issues and should work if your vLatest/PrevMonth variables contain a valid set analysis statement - and that there is no comma included which is always regarded as a parameter-delimiter. Therefore try this:

vMetric:

SUM( {< $1, FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< $1,   FLAG = {'Y'} >} AMOUNT_2 )

$(vMetric (vLatestMonth)) / $(vMetric(vPrevMonth))

- Marcus

rubenmarin

Hi rugerm when calling a variable you can pass different parameters, each one spearated by commas:

var(parameter1, parameter2)

Then $1 is used to get the first parameter, $2 for the second, etc.. So i think that vMetric should be:

SUM( {< $($1), FLAG = {'Y'} >} AMOUNT_1 ) / SUM ( {< $($1),   FLAG = {'Y'} >} AMOUNT_2 )

Anonymous
Not applicable

Hi i am start in this, you can help me ?

rutger_jansen
Contributor III
Contributor III
Author

Thanks very much Marcus

rutger_jansen
Contributor III
Contributor III
Author

Thanks Ruben, much appreciated

rutger_jansen
Contributor III
Contributor III
Author

I can try, what is your question? Maybe it's better to create a new 'discussion' for the community? Go to your login > Inbox/Activity > Discussion >