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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
MatiasJR
Contributor
Contributor

Using GetObjectDimension in variable

Hey guys,

I have a Master Dimension defined as "State_City". It's two layers (i use hierarchy), so I can show measures for the State and the Cities in the same table column, according to the selection. For this, I use the function GetObjectDimension in the chart, as in:

=if(Getobjectdimension() = 'State', number_for_the_state, number_for_the_city)

Since I use this function in more than 1 place, i'd like to define a variabale "vNumber" with the expression above in the data load script, so instead of re-writing the expression every time I could just write in the chart:

=$(vNumber)

But when i define the variable in the data load script

let vNumber '=if(Getobjectdimension() = 'State', number_for_the_state, number_for_the_city)'

the function getobjectdimension() does not work. I tried changing the syntax, since the ' causes problems,  and in the end got to the expression below

let vNumber = '(IF(GetObjectDimension() = '&chr(39)&' State '& chr(39) &' , Number_for_the_state, number_for_the_city))';

The expression is evaluated by QS, but it still does not compute the function getobjectdimension.

Am I doing something wrong? How could I use this function in this case? I know it is a chart and not a script function, but since i'm only defining it in the script, and using it  in the chart, my guess is that it would work. 

Thanks in advance!

Labels (6)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Try:

SET vNumber = if(Getobjectdimension() = 'State', number_for_the_state, number_for_the_city);

 

And you must reference the variable in your chart expression using the $(variable) syntax.

-Rob

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Try:

SET vNumber = if(Getobjectdimension() = 'State', number_for_the_state, number_for_the_city);

 

And you must reference the variable in your chart expression using the $(variable) syntax.

-Rob

MatiasJR
Contributor
Contributor
Author

The combination of SET + $ worked perfectly. Thank you, Rob.