Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
The #1 reason QlikView customers adopt Qlik Sense is a desire for a modern BI experience. Read More
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Not applicable

How to assign multiple values to a single variable in script?

Hi All,

I am a newbie to QV, I am trying to assign multiple values to a single variable using LET as below,

Load * inline[

Num

1

2

3

4

];

Let val=Num;

Is it possible to display all the values of "Num"  when variable "val" is loaded, because when loaded I am getting Null for "val" instead of 1,2,3,4.

6 Replies
Highlighted
MVP
MVP

Re: How to assign multiple values to a single variable in script?

Data:

Load * inline

[

  Num

  1

  2

  3

  4

];

TempConcat:

LOAD Concat(Distinct Num,', ') as TempNum Resident Data;

Let val = FieldValue('TempNum',1);

Drop Table TempConcat;

Highlighted
Not applicable

Re: How to assign multiple values to a single variable in script?

Hi Manish,

Thanks for the reply.I want the values to be displayed one by one as loaded in inline table by using a variable as below,

In the listbox by using variable name

=$(val)

1

2

3

4

Sorry for the confusion.

Highlighted
MVP
MVP

Re: How to assign multiple values to a single variable in script?

Why you want to use variable in List Box..

You can simply use Field Num in list box... What is the point of creating variable!

Highlighted
Not applicable

Re: How to assign multiple values to a single variable in script?

My requirement consists of an expression to be evaluated and used in a "for" loop. I tried using the expression directly in for loop but it wouldn't work, so I am trying to evaluate the expression using "LET" and then using that variable in for, but even that is not working. So I am trying to evaluate the expression using "LET" first. The expression is

for i=num(Addmonths(MaxDate,-12,1)) to num(MaxDate)

Test1:

Load  *,

sum(Current12M) as Total,

Key

Resident Final

where Exists(Key);

Next i;

Highlighted
MVP
MVP

Re: How to assign multiple values to a single variable in script?

can you provide sample data and result you want to achieve using loop?

Highlighted
MVP & Luminary
MVP & Luminary

Re: How to assign multiple values to a single variable in script?

Hi Priyanka,

QlikView variables, in contrast to fields, can only hold a single value. In your initial example, you create a field Num with several values, which is fine, and then you are trying to assign all the values of Num to a variable val, which is incorrect.

If you want a single field value to be assigned to a variable, you can use one of the functions that can fetch the field value either from a table or from the value list. Check out the following functions:

Peek() lets you peek the field value from a table

FieldValue() lets you fetch a single value from a list of field values (disregarding of a table)

Conversely, when you need to use variables in data load statements, you can't use them directly. Instead, you need to use them within a $-sign expansion. For example:

LOAD

    $(num_variable) as Field1,

    '$(string_variable)' as Field2,

...

Check out my new book QlikView Your Business. In the book, I describe in detail how to use variables for a variety of analytical needs in the script and in the UI.

cheers,

Oleg Troyansky

Check out my new book QlikView Your Business: An expert guide to Business Discovery with QlikView an...