Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
jblomqvist
Contributor II

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
MVP
MVP

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

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()

31 Replies

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

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

MVP
MVP

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

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
Contributor II

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

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.

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

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.

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

try

If $(vDropField)=1 then

Drop Field Counter;

else TRACE "False"

ENDIF

jblomqvist
Contributor II

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

Hi Sunny,

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

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

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
Contributor II

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

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.

MVP
MVP

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

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 ......

Community Browser