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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
mkanaa123
Contributor
Contributor

Using variables in master items

hi all i have around 100 master items measures  are there ,

For each expression  in master item  , i am writing the expression as

Expression1:

Sum(IF(XNum= 1,Field1,
if(XNum=2,Field1/SomeField1,
if(XNum=3,Field1-SomeField1))))

 

Expression2:

Sum(IF(XNum= 1,Field2,
if(XNum=2,Field2/SomeField1,
if(XNum=3,Field2-SomeField1))))

 

Now i want to automate this expression using one variable for XNum

And use that variable in master item expression .

Can anyone please help me

Going forward i want to add one more XNum=4 and Xnum=5  No need of going everywhere and change the expression everytime in each expression for each masteritem,

 

Can anyone please help me

 

I dont want in backend script , 

I need in front end variable .

 

 

Labels (1)
3 Replies
mkanaa123
Contributor
Contributor
Author

anyoneplease help

Channa
Specialist III
Specialist III

load * inline [NUM

1

2

3....]

create variable vNum =NUM

Sum(IF(XNum= 1,Field2,
if(XNum=2,Field2/SomeField1,
if(XNum=3,Field2-SomeField1))))

change expression as below

Sum(IF(XNum= $(vNum),Field$(vNum),
if(XNum=Field$(vNum),Field$(vNum)/SomeField1,
if(XNum=Field$(vNum),Field$(vNum)-SomeField1))))

 

this is just same will help to change field based on filter selection

use filter as NUM column which is inline load

 

Channa
AustinSpivey
Partner - Creator
Partner - Creator

I think you're needing dollar-sign expansion with parameters. Here's a Qlik Help article about it. In your case, you can create a new variable that will act like a custom function:

Sum(If(XNum=1, $1,if(XNum=2, $1 / SomeField1,if(XNum=3, $1 - SomeField1))))

AustinSpivey_0-1677948650990.png

Then you can use the new function like this, by simply using the desired fieldname as a parameter in the new variable:

AustinSpivey_1-1677948712566.png

You'll then only need to update the MyFunc variable in the future.

 

Austin Spivey | Principal Consultant @ Arc Analytics
ArcAnalytics.co | Add me on LinkedIn