Qlik Community

New to Qlik Sense

If you’re new to Qlik Sense, start with this Discussion Board and get up-to-speed quickly.

Announcements
IMPORTANT security patches for GeoAnalytics Server available to download: READ DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to use variables in load scripts

Hi there.

I need to use a variable whose value is set in a previous stage of the data load process in a further section of the same load script.

The variable contains a date and I need to calculate the difference between its value and the dates in another field to build up a new field containing that difference. So:

Setting the value of the variable

Noname.jpg

And vMaxDate will contain the most recent date in my data table (this part works perfectly).


Using the variable

Later in the load script I'd something like (simplified example):

LOAD

Id,

Exped.,

Company,

...

Registration_date,

(vMaxDate - Registration_date) as Time_in_system,

...

And this is what I can't make work.

Any suggestion, guidance, comment will be highly appreciated.

Many thanks in advance.

M.

1 Solution

Accepted Solutions
jonathandienst
Partner
Partner

You need to enclose a variable in a $() expansion in a load statement, if vMaxDate is a number, like this

...

Registration_date,

($(vMaxDate) - Registration_date as Time_in_system,

...

Or if vMaxDate is formatted as a date:

...

Registration_date,

('$(vMaxDate)' - Registration_date as Time_in_system,

...

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

View solution in original post

2 Replies
jonathandienst
Partner
Partner

You need to enclose a variable in a $() expansion in a load statement, if vMaxDate is a number, like this

...

Registration_date,

($(vMaxDate) - Registration_date as Time_in_system,

...

Or if vMaxDate is formatted as a date:

...

Registration_date,

('$(vMaxDate)' - Registration_date as Time_in_system,

...

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Brilliant!

Thanks Jonathan.

M.