Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
agigliotti
Partner - Champion
Partner - Champion

let's try as below:

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

View solution in original post

11 Replies
sunilkumarqv
Specialist II
Specialist II

Please try change set instead let


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

Anonymous
Not applicable
Author

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?

arvind1494
Specialist
Specialist

Try to create variable in variable overview instead of script.

it may works

Anonymous
Not applicable
Author

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.

agigliotti
Partner - Champion
Partner - Champion

let's try as below:

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

kkkumar82
Specialist III
Specialist III

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?

marcus_sommer

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

Anonymous
Not applicable
Author

Hi Andrea, thanks alot, that worked!