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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Defining expressions to re-use across different objects?

Hi all,

It is time consuming an confusing to have to re-write every expression when creating a new object. Is there a better way? I know that you can re-use expressions within the same object, or copy and paste them across objects, but what about defining an expression, giving it a name and using it by that name in different objects?

Thanks in advance.

Hasan

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

You could define a variable with the text of the expression, and then substitue the variable wherever the expression is needed.

For example, Let SalesVar='Sum(Sales)'. then in the chart, you could use $(SalesVar) in place of Sum(Sales)

View solution in original post

5 Replies
Not applicable
Author

Hi,

You could define a variable with the text of the expression, and then substitue the variable wherever the expression is needed.

For example, Let SalesVar='Sum(Sales)'. then in the chart, you could use $(SalesVar) in place of Sum(Sales)

Not applicable
Author

I put all my commonly used expressions at the top of the script so they are all together and easy to review.

Create them using SET and these then get written out as variables on reload. As Vidyut says, you can then reference the contents using $(varname)

Regards,

Gordon

Not applicable
Author

Great tip gentlemen!

I can't believe I haven't been utilizing this. My current project seems to use the same formulas over and over and I've been retyping them each time.

A variable can also be used to define a reusable Set Analysis expression. I am using a lot of flags, so all of my formulas seem to contain {<Flag={1}>}. You can set up a variable vFlag = '{<Flag={1}>}'. Then in each formula, you can use Sum($(vFlag) Field) in place of Sum({<Flag={1}>} Field). In this example, it's not that much shorter, but with longer Set Analysis expressions, it could be a great time saver. If nothing else, it will reduce the number of curly brackets I have to type!

Not applicable
Author

That's exactly what I was looking for, thanks a lot! Smile

amien
Specialist
Specialist

Thanks for this topic. really useable for maintenance