Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
felcar2013
Partner - Creator III
Partner - Creator III

include variable in set expression

hi

i have defined this variable:

set vGender = sum({$<gender_ID={1,2}>} %contact_counter)/sum({$<gender_ID={1,2}>} total %contact_counter)

now i want to use the same variable in this expression, where I split the field name, but i do not want to select the different values with a list box or any other sheet object:

=RangeMax(

 

  (sum({$<gender_ID={1}>} %contact_counter)/sum({$<gender_ID={1,2}>} total %contact_counter))

  ,

  (sum({$<gender_ID={2}>} %contact_counter)/sum({$<gender_ID={1,2}>} total %contact_counter))

  )

please advice on this

thanks

felipe



					
				
			
			
				
			
			
			
			
			
			
			
		
1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

On reconsideration, if your define vGender like this:

set vGender = sum({<gender_ID={$1}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)

This is now a parameterised macro and you would use it like this

=RangeMax($(vGender(1)), $(vGender(2)))

 

The original form would be

  =$(vGender(1,2))

If that does not work, you might need to include an extra = in the set statement:

 

set vGender = =sum({<gender_ID={$1}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

5 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Felipe

Perhaps I misunderstood your requirements, but the simple answer is you cant. You have defined vGender, but what you need is different. Why not simply use another variable?

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

On reconsideration, if your define vGender like this:

set vGender = sum({<gender_ID={$1}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)

This is now a parameterised macro and you would use it like this

=RangeMax($(vGender(1)), $(vGender(2)))

 

The original form would be

  =$(vGender(1,2))

If that does not work, you might need to include an extra = in the set statement:

 

set vGender = =sum({<gender_ID={$1}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
felcar2013
Partner - Creator III
Partner - Creator III
Author

thanks, first time i use this, it worked

i declared the vGender and then used as $(vGender(1)) and $(vGender(2)) for the rangemax()

I did not use the =$(vGender(1,2)) . what did you mean with the original ? 

i check this in the manual , but i do not understand how it is used. What does the " $1 " or "$2", etc. means?

is it the first set of values of my first field and $2 the second set of values of the next field included in the expression?

for vGender(1,2) you meant with original, that i have for that variable, a list of two parameters? do i need to use this in the script?

thanks

felipe

jonathandienst
Partner - Champion III
Partner - Champion III

A variable described this way behaves like a parameterised macro (or user defined function, if you prefer). The $1 refers to the first parameter, $2 to the second and so on. When the variables is evaluated, it uses the values passed in the brackets.

So

=$(vGender(1))

is the same as

=sum({<gender_ID={1}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)

And

=$(vGender(2))

is the same as

=sum({<gender_ID={2}>} %contact_counter)/sum({<gender_ID={1,2}>} total %contact_counter)


I assumed that because you stated vGender that way in your post that you might want to use it that way. So there is no reason to use $(vGender(1,2)). (It would not work anyway as the comma is the separator between two parameters and if it did it would always return 1).

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
felcar2013
Partner - Creator III
Partner - Creator III
Author

hi thanks

it is very clear

Felipe