Qlik Community

Ask a Question

New to Qlik Sense

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

Announcements
Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Creator II
Creator II

loop inside load statement

Hi all.

Is there any possibility to use loop or something like it inside load statement?

I have an excel table which is edited manually by users.  From this table, I always need to load the first 4 columns with names like A, B, C, D and all columns that ended with the symbol "_GRE". Since users can delete some columns with a symbol "_GRE"  or add new ones, I can’t simply list them in the LOAD. I think such a load can be implemented in a loop, but I don’t understand how to do it. Can anyone help me with solution?

1 Solution

Accepted Solutions
MVP
MVP

In that case, try like:

temp:

Load * From <> where recno()=1;

let j=0;
For i=1 to NoOfFields('temp')

   if $(j)<5 and WildMatch(FieldName($(i), 'temp'), '*_GRE') then
     j=j+1;
     let vField$(j)='['&FieldName($(i), 'temp')&']';
   end if
Next

t1:
Load
   $(vField1),
   $(vField2),
   $(vField3),
   $(vField4)
From <>;

Drop table temp;

View solution in original post

4 Replies
MVP
MVP

You can try like:

//Load all fields using '*' with single record

temp:

Load * From <> where recno()=1;

//Then find the first four fields and put them in variables

Let vField1='['&FieldName(1, temp)&']';
Let vField2='['&FieldName(2, temp)&']';
Let vField3='['&FieldName(3, temp)&']';
Let vField4='['&FieldName(4, temp)&']';

//Load all records for these fields

t1:

Load
    $(vField1),
    $(vField2),
    $(vField3),
    $(vField4)

From <>;

Drop table temp;

Creator II
Creator II

Hi @tresesco 

Thank you for your idea. Unfortunately this method can't help me to load with first for columns all columns that ended with the symbol "_GRE".

MVP
MVP

In that case, try like:

temp:

Load * From <> where recno()=1;

let j=0;
For i=1 to NoOfFields('temp')

   if $(j)<5 and WildMatch(FieldName($(i), 'temp'), '*_GRE') then
     j=j+1;
     let vField$(j)='['&FieldName($(i), 'temp')&']';
   end if
Next

t1:
Load
   $(vField1),
   $(vField2),
   $(vField3),
   $(vField4)
From <>;

Drop table temp;

View solution in original post

Creator II
Creator II

@tresesco  Thank you much for your idea!