Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
ananyaghosh
Creator III
Creator III

FirstSortedValue cannot be used in script

Hi,

I have done this thing:

Employee:

load * Inline [

Employee ID, Age, Customer Name, Sales

Sandip Ghosh, 34, Customer1, 1000

Ananya Ghosh, 29, Customer2, 1200

Amit Das, 35, Customer3, 3000

Kaushik Dhar, 55, Customer4, 5400

Sudhir Ghosh, 74, Customer5, 5980

Sandip Ghosh, 34, Customer6, 54670

Sandip Ghosh, 34, Customer7, 45675

Kaushik Dhar, 55, Customer8, 15400

Kaushik Dhar, 55, Customer9, 45400

Sudhir Ghosh, 74, Customer10, 6598

Ananya Ghosh, 29, Customer2, 16200

Sudhir Ghosh, 74, Customer5, 5980

Sudhir Ghosh, 74, Customer6, 2980

Ananya Ghosh, 29, Customer2, 12900

Ananya Ghosh, 29, Customer2, 12070

];

LET vHighestSalary = FirstSortedValue([Customer Name], -Sales);

SET vSalary =  'Highest Salary = ' & vHighestSalary;

Now show the variable in textbox object as =$(vSalary), but it only show  'Highest Salary = ' and value is not showing.

12 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

It needs to be in a load statement:

     T_Fsv:

     LOAD FirstSortedValue([Customer Name], -Sales) As Fsv

     Resident Employee;


     Let vHighestSalary = Peek('Fsv');

     Let vSalary =  'Highest Salary = ' & vHighestSalary;

     DROP TABLE T_Fsv;


HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
anbu1984
Master III
Master III

You can directly write the below expression in Text box or you assign the FirstSortedValue() expression to a variable in UI using Variable overview


='Highest Salary = ' & FirstSortedValue([Customer Name], -Sales)

ananyaghosh
Creator III
Creator III
Author

If semicolon is used at the end of the script it will give garbage error. So drop that semicolon : ;

anbu1984
Master III
Master III

You are right. Fixed the previous post

ananyaghosh
Creator III
Creator III
Author

Can it be written as:

T_Fsv:

     LOAD [Customer Name], max(Sales) As Fsv

     Resident Employee group by [Customer Name];


     Let vHighestSalary = Peek('Fsv');

     Let vSalary =  'Highest Salary = ' & vHighestSalary;

     DROP TABLE T_Fsv;

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Or change your script by dropping the LET vHighestSalary... statement and modifying the SET statement into something like:

SET vSalary='Highest Salary = ' & FirstSortedValue([Customer Name], -Sales);

No need to change any expressions in the UI.

ananyaghosh
Creator III
Creator III
Author

I have tried this:-

LET vHighestSalary = FirstSortedValue([Customer Name], -Sales);

SET vSalary =  'Highest Salary = ' & vHighestSalary;

but it does not work for me.

anbu1984
Master III
Master III

LET vHighestSalary = 'FirstSortedValue([Customer Name], -Sales)';

SET vSalary =  'Highest Salary = ' & $(vHighestSalary);

In Text box, use this expr

=$(=vSalary )

Peter_Cammaert
Partner - Champion III
Partner - Champion III

That's because the LET statement evaluates the expression on the right of the equal sign, and that part is invalid (or doesn't return a value).

The SET statement doesn't do a such thing. It just stores everything after the equal sign as literal text in your variable for later use.

Drop the LET statement, and use the SET statement version from my post.

Or use the version that Anbu posted.