Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
jblomqvist
Specialist
Specialist

How can I write an If statement for a Drop Field statement like this?

Hi all,

I am trying to write a query like below:

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If($(vDropField)=1, Drop Field Counter, False);

Basically I want to drop the field is the vDropField variable contains 1, else don't drop the field.

It doesn't work when I write it. Any idea how to do this please?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Try

LET vDropCustomerGroup = If( '$(vDropCounterField)' = 'Yes','',', ApplyMap(''Customers_Map'',CustomerCode, ''Not Found'') as CustomerName');


Note the use of two single quotes as escape character within the ApplyMap()

View solution in original post

31 Replies
sunny_talwar

May be like this:

TableA:

LOAD Floor(Rand() * 17) + 10 as Test,

          1 as Counter

AutoGenerate 23;

If $(vDropField) = 1 then

     DROP Field Counter, False;

ENDIF

swuehl
MVP
MVP

You can keep to the example in the HELP:

if $(vDropField) =1 then; drop field Counter; end if;

edit:this should also work

if  vDropField =1 then; drop field Counter; end if;

jblomqvist
Specialist
Specialist
Author

Hi Sunny,

When I try it:

TableA:

LOAD

floor(RAND()*17)+10 as Test,

1 as Counter

AutoGenerate 23;

If $(vDropField)= 1 then

     DROP Field Counter;

ENDIF;

I get the following error message:

Did I miss something?

I have created a Input Box in the UI called vDropField which has value of 1 to test it.

sunny_talwar

Can you add a Trace statement for your variable?

TRACE $(vDropField);

Exit Script;

Add this at the top of your script just to check if $(vDropField) is showing one or not.

Kushal_Chawda

try

If $(vDropField)=1 then

Drop Field Counter;

else TRACE "False"

ENDIF

jblomqvist
Specialist
Specialist
Author

Hi Sunny,

It doesn't come through in the script when I check the Variables tab.

sunny_talwar

Can you check variable overview to see if you can see 1? Also can you make sure you have not mis-spelled or made a typo with the upper case lower case?

jblomqvist
Specialist
Specialist
Author

Hi Swuehl,

The first code doesn't run and throws the same error as reply to Sunny above.

And second code runs but I still have the Counter field available even though vDropField variable carries 1.

swuehl
MVP
MVP

Where do you check this variable tab?

You should set the vDropField variable to 1 (and not to an expression like =If( A= B, 1) ) and check the correct case sensitiv spelling in all places.

For example, in the script:

Set vDropField = 1;

...

If vDropField = 1 ......