Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How can you use the distinct function in a script?

I have an expression which works fine in an app, however when I try to put this into a script, it doesn't work. The below is what I'm looking to achieve in the script;

sum(distinct{<[DG.class]={'1'}>}[DG.uomactqty])

Any ideas?

2 Replies
stascher
Partner - Creator II
Partner - Creator II

I think the issue isn't the use of distinct but rather  that the chart function sum() and the script function sum() are not interchangeable, particularly where set analysis is concerned.

You can probably accomplish your goal with something like:

Table:

Load sum(distinct [DG.uomactqty]) as total  resident DG group by <DG.something> where DG.class='1';

Then you can assign the total to a variable using the peek function.

Anonymous
Not applicable
Author

SUM syntaxes:

  • SUM chart function syntax: Sum([{SetExpression}] [DISTINCT] [TOTAL [<fld {,fld}>]] expr])
  • SUM script function syntax: sum ( [ distinct] expr)


The SetExpression does not works in sum script function like works in sum chart function