Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Simplify code in load statements

I have some very long formulas within a Load Statement and some of the fields depend on the value of the field above.

Rather than nest the code for the line above in the new line which gets difficult to read is there a way to define a variable within the load or another way to simplify it?

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

You can use preceeding loads to load from the table so far and add fields based on other fields. For a simple example:

[Something]:
LOAD *
,if("Category"='A' and "Month"=date(20090501,'YYYYMMDD'),"Amount") as "May 09 Category A Amount"
;
LOAD *
,date(monthstart("Date")) as "Month"
;
LOAD
date(date#(20081231,'YYYYMMDD')+recno()) as "Date"
,mid('ABCDE',ceil(rand()*5),1) as "Category"
,ceil(rand()*1000) as "Amount"
AUTOGENERATE today()-date#(20081231,'YYYYMMDD')
;

View solution in original post

2 Replies
johnw
Champion III
Champion III

You can use preceeding loads to load from the table so far and add fields based on other fields. For a simple example:

[Something]:
LOAD *
,if("Category"='A' and "Month"=date(20090501,'YYYYMMDD'),"Amount") as "May 09 Category A Amount"
;
LOAD *
,date(monthstart("Date")) as "Month"
;
LOAD
date(date#(20081231,'YYYYMMDD')+recno()) as "Date"
,mid('ABCDE',ceil(rand()*5),1) as "Category"
,ceil(rand()*1000) as "Amount"
AUTOGENERATE today()-date#(20081231,'YYYYMMDD')
;

Not applicable
Author

Thank you - very helpful