Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

error loading script using variables


Hello,

I´m trying to load a table using a where clause that has a variable, but i got an error.

I have a field Period that is define with the 12 months. This field always have One value selected.

I created a variable vPeriod = Period. When I select the Period my variable vPeriod changes.

I have a table with 2 fields (Month and Amount), and I try to load the table with a where clause , trying to load data where Month>=vPeriod

I have this script but it doesnt work if I try to use the variable $(vPeriod) instead of a value (3 in the script)

Period:

LOAD * INLINE [
Period
1
2
3
4
5
6
7
8
9
10
11
12
]
;

Data_aux:
LOAD * INLINE [
Month, Value
1, 100
2, 200
3, 300
4, 400
5, 500
6, 600
7, 700
8, 800
9, 900
10, 1000
11, 1100
12, 1200
]
;

let vMonth
= $(vPeriod);

//let vMonth = 3;

Data:

LOAD

Month,

Value as Amount

Resident Data_aux

Where Month >= $(vMonth);

Drop Table Data_aux;

I send you the qvw file.

Thank you very much for your help

1 Solution

Accepted Solutions
pgrenier
Partner - Creator III
Partner - Creator III

Hello,

You could try adding a trigger on the Period field (Settings -> Document properties)

FieldTriggers.jpg

The button will appear as Add Action(s) when no actions have yet to be defined.

AddActions.jpg

You shall find the modified qvw file in attachment,

Regards,

Philippe

View solution in original post

6 Replies
tresesco
MVP
MVP

Try putting single quotes around variable expansion like:

Where Month >= '$(vMonth)' ;

Not applicable
Author

Hi tresesco,

It doesn´t work. It seems that the variable is null

pgrenier
Partner - Creator III
Partner - Creator III

Hello,

You could try adding a trigger on the Period field (Settings -> Document properties)

FieldTriggers.jpg

The button will appear as Add Action(s) when no actions have yet to be defined.

AddActions.jpg

You shall find the modified qvw file in attachment,

Regards,

Philippe

maxgro
MVP
MVP

see attachment

I simplified your script and user interface, hope is what you want

Data_aux:

LOAD * INLINE [

    Month, Value

    1, 100

    2, 200

    3, 300

    4, 400

    5, 500

    6, 600

    7, 700

    8, 800

    9, 900

    10, 1000

    11, 1100

    12, 1200

];

Data:

LOAD Month,

    Value as Amount  

Resident Data_aux

Where Month >= $(vPeriod);

Drop Table Data_aux;

Not applicable
Author

Find the attachment.

Hope this will help u..!

Not applicable
Author

Thank you very much it works now