Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
mazacini
Creator III
Creator III

Load static value for variable in script

Hi

I have a table with a ItemVal field, which is a numerical field.

I want to create a static value for the total value of the ItemVal field.

I thought this would work, but it doesn't.

Let vItemValTotal = sum(ItemVal);

Is this possible?

I know I can enclose in single apostrophe and use it with $ expansion, but I don't want to do that.

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Like this:

Temp:

LOAD sum(ItemVal) as SumOfItemVal FROM ...MyTable...;

LET vItemValTotal = peek('SumOfItemVal');

Drop Table Temp;


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
Gysbert_Wassenaar

Like this:

Temp:

LOAD sum(ItemVal) as SumOfItemVal FROM ...MyTable...;

LET vItemValTotal = peek('SumOfItemVal');

Drop Table Temp;


talk is cheap, supply exceeds demand
mazacini
Creator III
Creator III
Author

Thanks Gysbert.

Would you mind if I ask you some questions?

So my LET statement in isolation does not actually perform the SUM calculation?

Does the LET statement in your example have to follow immediately on from the LOAD?

I've only ever used PEEK in the context of adding a field to a table based on data already in that table.

But from your solution, it operates across the model as a whole also? I assume it is significant that the "SumOfItemVal' field contains only a single value?

Kind Regards

Joe

mazacini
Creator III
Creator III
Author

BTW, I should point out that your solution worked perfectly!

Gysbert_Wassenaar

So my LET statement in isolation does not actually perform the SUM calculation?

That's correct. The Sum can only be calculated in a load statement.

Does the LET statement in your example have to follow immediately on from the LOAD?

No, anywhere after the Temp table with the sum is created and before that table is dropped.

But from your solution, it operates across the model as a whole also? I assume it is significant that the "SumOfItemVal' field contains only a single value?

Without passig an additional parameter peek will use -1 to retrieve a value from the last row of the source table. If the field exists in more then one table then you need to specify the name of the source table too.


talk is cheap, supply exceeds demand
mazacini
Creator III
Creator III
Author

That's great, Gysbert.

Thank you for your help.

Joe