Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

Highlighted
rutger_jansen
New 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

Tags (2)
1 Solution

Accepted Solutions
MVP & Luminary
MVP & Luminary

Re: Variable with parameter

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

6 Replies
MVP & Luminary
MVP & Luminary

Re: Variable with parameter

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

Re: Variable with parameter

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 )

grupotvieira
New Contributor

Re: Variable with parameter

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

rutger_jansen
New Contributor III

Re: Variable with parameter

Thanks very much Marcus

rutger_jansen
New Contributor III

Re: Variable with parameter

Thanks Ruben, much appreciated

rutger_jansen
New Contributor III

Re: Variable with parameter

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 >