Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
aetingu12
Creator
Creator

Creating a new field from expression and passing value

Dear all,

I have a created a simple listbox called Views by writing this expression :

=ValueList('a','b')

Basically, I want tp pass the selection to another field to do calculations. ie if a is selected then I should be able to refer to it from another expression by writing something like:

if(view = a, sum(sales), if(view = b, cost,null))

Any guidance would be more than appreciated.

Regards,

Aksel

1 Solution

Accepted Solutions
rajivmeher
Creator
Creator

Hi aetingu12

If I understand right, you want to change a field in your calculation based on a listbox selection (correct me if I am wrong).

You can achieve it in another way. Use a inline load with selections you want to do as follows:

1.

CalcSwitch:

Load * inline

[

%ColLabel,%ColName


'a','sum(sales)'


'b','cost'

];

2. Use %ColLabel in a listbox. You will be using this to change your calculation selection.

3. In calculation use the following:

$(=%ColName)


This will change the calculation based on your selection as per what you mention in the inline table.


Regards

Rajiv.

View solution in original post

5 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Check this link.

Missing Manual - ValueLoop() & ValueList()

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
jonathandienst
Partner - Champion III
Partner - Champion III

Valuelist() values are not fields and so they cannot be selected.

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

Hi aetingu12

If I understand right, you want to change a field in your calculation based on a listbox selection (correct me if I am wrong).

You can achieve it in another way. Use a inline load with selections you want to do as follows:

1.

CalcSwitch:

Load * inline

[

%ColLabel,%ColName


'a','sum(sales)'


'b','cost'

];

2. Use %ColLabel in a listbox. You will be using this to change your calculation selection.

3. In calculation use the following:

$(=%ColName)


This will change the calculation based on your selection as per what you mention in the inline table.


Regards

Rajiv.

aetingu12
Creator
Creator
Author

Much appreciated. Exactly what I wanted to do! Thank you.

HirisH_V7
Master
Master

Hi Aksel ,

Value List can be used only to create synthetic dimension, But even if u want it to get it such way means. you can create a field from your Scriptside using match function.

=If(MATCH(Customer,'A-2-Z Solutions','Aadast'),'A',

If(MATCH(Customer,'A Superior System','A&R Partners'),'B','Other'))

Regards,

Hirish

HirisH
“Aspire to Inspire before we Expire!”