Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Talk to Experts, a LIVE Q&A Webinar. Bring your Qlik Sense Business questions on Aug. 4th. Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor
Contributor

Aggr Function with GetFieldSelection and Set Expression into Script Variable

Hi all,

I have an issue with the creation of a variable in the script part, however it seems to be problematic, hope somebody can have a quick look

This is my data

  t1

IdDimVal
id1a5
id1b7
id1c19
id2a8
id2b10
id2c15

Another field called "DimSelect" used in the set analysis later and refered to by the GetFieldSelections expression is created by ->

Nav:

Load Distinct

     Dim as DimSelect

Resident t1;

Now, creating chart function works fine:

=aggr(max( {<Dim={'$(=GetfFeldSelections(DimSelect))'}>} Val), Id)

However, I would like to have this chart function as a variable created in the script, and unfortunately it does not work

Script:

let vAggr = 'aggr(max( { <Dim = {"$(=GetFieldSelections(DimSelect))" }> }  Val), Id)';

Chart:

=$(vAggr)

Does anyone possibly know what I am doing wrong? The issue seems to be with the expression GetfieldSelections(DimSelect), because inserting a value like "b" instead of GetFieldSelections expression also works fine.

Thanks!

1 Solution

Accepted Solutions
Highlighted
Partner
Partner

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

let's try as below:

let vAggr = 'aggr(max( { <Dim = {"' & chr(36) & '(=GetFieldSelections(DimSelect))" } > }  Val), Id)';

View solution in original post

11 Replies
Highlighted
Specialist II
Specialist II

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Please try change set instead let


Set vAggr = 'aggr(max( { <Dim = {"$(=GetFieldSelections(DimSelect))" }> }  Val), Id)';

Highlighted
Contributor
Contributor

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Hi Sunil, thanks for your quick reply. No, unfortunately it does not work, but inserting "b" instead of $(=GetFieldSelections(DimSelect)) works also with Set instead of Let and gives me results.
Or do I need to change something in the chart function as well?

Highlighted
Specialist
Specialist

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Try to create variable in variable overview instead of script.

it may works

Highlighted
Contributor
Contributor

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Hi Arvind, yes it works when I create this variable

formula -> aggr(max( {<Dim={'$(=GetFieldSelections(DimSelect))'}>} Val), Id)

in the variables part of the "front end", thanks for the tip. However, ideally and especially for upcoming maintenance, I would need it in the script load.

Highlighted
Partner
Partner

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

let's try as below:

let vAggr = 'aggr(max( { <Dim = {"' & chr(36) & '(=GetFieldSelections(DimSelect))" } > }  Val), Id)';

View solution in original post

Highlighted
Specialist III
Specialist III

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Hi Fels,

Aggr is a front end function it cannot be used in script level.

One question pinching me,

Do you want the function to be executed in the backend ? or just want to create a variable with the definition using Aggr?

Highlighted
Specialist III
Specialist III

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Highlighted
MVP & Luminary
MVP & Luminary

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

IMO is the creation of expression-variables within the script often not very beneficial because the used $-sign need a special treatment and also the various quotes and brackets need more attention as using an expression directly within an object. Should there be really multiple (between different applications) re-usable variables it would be better to store them externally as file and loading them as table and creating then the variables within a loop. Within this posting you will find various examples how such logic could be implemented (and many more to): Variables

Beside this you could use in your case a different set analysis approach to get the same result:

set vAggr = aggr(max({ <Dim = p(DimSelect)> }  Val), Id);

- Marcus

Highlighted
Contributor
Contributor

Re: Aggr Function with GetFieldSelection and Set Expression into Script Variable

Hi Andrea, thanks alot, that worked!