Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
JustinDallas
Specialist III
Specialist III

Evaluate "Only" in Script

Hello Folks,

I'm looking to evaluate an Only statement in the script.  I have an example below.

[Test]:
Load * Inline
[
'Name', 'Food',
'Bob',  'Apple',
'Carl', 'Iberian Ham'
]
;

Set vBestFood = Only({<[Name]={'Bob'}>} Food)
;

Trace 'The best food here is $(vBestFood)'
;

Exit Script
;

 

I am trying to get the following output:

"The best food here is Apple"

 

Any help is greatly appreciated.

Labels (4)
1 Solution

Accepted Solutions
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Justin,

Unfortunately this can't be done as described - neither Only() nor Set Analysis can be used in the Script - these are both Chart functions/features.

In the script, you should think similarly to the SQL logic - load the desired data row with a WHERE condition, and then fetch the result into a variable using the Peek() function.

Join us at the Masters Summit for Qlik in Orlando or in Dublin to learn advanced Set Analysis, scripting, data modeling, performance, visualizations, and more - delivered by some of the best Qlik experts in the world!

View solution in original post

2 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Justin,

Unfortunately this can't be done as described - neither Only() nor Set Analysis can be used in the Script - these are both Chart functions/features.

In the script, you should think similarly to the SQL logic - load the desired data row with a WHERE condition, and then fetch the result into a variable using the Peek() function.

Join us at the Masters Summit for Qlik in Orlando or in Dublin to learn advanced Set Analysis, scripting, data modeling, performance, visualizations, and more - delivered by some of the best Qlik experts in the world!

marcus_sommer

It's not possible to assign certain - aggregated and/or with any conditions - table/field-results to a variable. If you want to grab such values you will need a load-statement which fetched this data and then you could grab this value per peek() or fieldvalue().

In your probably simplified example you could get the wanted results per:

let vBestFood = fieldvalue('Food', fieldindex('Name', 'Bob')); trace $(vBestFood);

but with a bit more complex data it's rather unlikely that they are unique enough for such an approach.