Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
kmstephenson
Creator
Creator

IF/END IF within LOAD?

Hi All,

Is similar logic to use within a LOAD statement? There are a few variables that I only want to load in the data set if my $(vSource) variable resolves to a specific source. Otherwise, I don't want the variables to be pulled in the dataset. IF/END IF doesn't appear to work within the LOAD statement.

Thanks!

Tina

1 Solution

Accepted Solutions
sunny_talwar

I don't think it is possible with the load, but you can set up a variable before to check which fields you want to bring in. For instance you have 6 fields: F1, F2, F3, F4, F5, F6 and you only want to bring last three when it is from a specific source, then you can try this

LET vFields = If($(vSource) = 'Path....', 'F4, F5, F6', '0 as Dummy');

LOAD F1,

          F2,

          F3,

          $(vFields)

FROM ....

View solution in original post

4 Replies
sunny_talwar

Can you share what you have tried thus far? Or may be try this:

IF $(vSource) = 'Path.....' then

     LOAD *

     FROM $(vSource);

ENDIF;

kmstephenson
Creator
Creator
Author

I was hoping to use the IF THEN logic(or something similar) within the LOAD... I don't do a LOAD * because I'm only pulling in a subset of variables and also using TEXT(), APPLYMAP() etc. There are a few fields (in the example var11-var13) that are only available for a certain source that I would like to include if run for that source...

     LOAD var1,

               TEXT(var2) AS var2,

               .

               .

               .

              var10


              IF $(vSource) = 'Source' THEN

              ,var11

              ,var12

              ,var13

              END IF


     FROM $(vSource);

END IF;

sunny_talwar

I don't think it is possible with the load, but you can set up a variable before to check which fields you want to bring in. For instance you have 6 fields: F1, F2, F3, F4, F5, F6 and you only want to bring last three when it is from a specific source, then you can try this

LET vFields = If($(vSource) = 'Path....', 'F4, F5, F6', '0 as Dummy');

LOAD F1,

          F2,

          F3,

          $(vFields)

FROM ....

kmstephenson
Creator
Creator
Author

Thank you!