Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Map Load If Function

Hello All,

I have the following mapping load:

if((ApplyMap('Map_DATASOURCE', THEVALUE)) = 'SuperUser','No') as ENDUSEREDIT,

It simply takes 'THEVALUE' to the Map_DATASORCE, and then applies an if based on the returned value.

If the value is 'SuperUser' put 'No' as the data.

What I have been trying to do is the else part. I have the formattin gbut can only match the value to another value. I would like to say "else, store the original returned vaule"... Like this:

if((ApplyMap('Map_DATASOURCE', THEVALUE)) = 'SuperUser','No', ORIGINAL VALUE RETURNED FROM MAP) as ENDUSEREDIT,

I just do not know what ORIGINAL VALUE RETURNED FROM MAP should be.

I have a feeling this would work but it is probably not good for performance as it does two mappings:

if((ApplyMap('Map_DATASOURCE', THEVALUE)) = 'SuperUser','No',ApplyMap('Map_DATASOURCE', THEVALUE)) as ENDUSEREDIT,

Any help would be appreciated.

Regards,

Jim

13 Replies
Not applicable

Re: Map Load If Function

If you are using an If Statement you would be better off to base it on the core data and just applymap where needed i.e. in your if statement use the original data?

kouroshkarimi
Contributor III

Re: Map Load If Function

Could you use a variable? e.g:

Let v_map = ApplyMap('Map_DATASOURCE', THEVALUE);

if( '$(v_map)' = 'SuperUser', 'No' , '$(v_map)' ) as ENDUSEREDIT;

Not applicable

Re: Map Load If Function

Hello Felim,

The original data is just an ID which does not help. The values I need are in the map table so the map part is a must, surely? ie, you take the ID, look it up in the map, then bring back the value. I then do the if on this value. - cannot see any other way to do this other than a join... which also does not really help for the if.

Regards,

Jim

Not applicable

Re: Map Load If Function

Hello Kouroshkarimi,

This looks promising.

I will give this a go and let you know how I get on.

Regards,

Jim

Not applicable

Re: Map Load If Function

Your misunderstanding my point, basically you would use the ID´s in your if statement rather than using an apply map.

If (THEVALUE = 1 OR THEVALUE = 2,'No',ApplyMap('Map_DATASOURCE', THEVALUE)) AS ENDUSEREDIT

This avoids mapping twice

Not applicable

Re: Map Load If Function

Hmmm, dont seem to understand.

To do an if statement I need the values which can only come from grabbing via the map load. The values I need are not in the initial table hence the mapping load. The initial table only holds IDs. Not the values that I am interested in.

To do the if you suggest is not possible with the data...

So the If(THEVALUE = 1 or THEVALUE = 2 cannot be done as THEVALUE is only ID.

I think this makes sense?

Not applicable

Re: Map Load If Function

Hello Kouroshkarimi,

Having trouble adding the variable to the script. Have not dont this part before and cannot find where to add this to qv.

I am on version 9.

Any help would be appreciated.

Regards,

Jim

Not applicable

Re: Map Load If Function

No that makes no sense, you have the data infront of you.  Doing it the way Kourosh is saying is basically doing what you have done but means you have to type less..

basically Apply Map is a lookup, it matches ID in both tables.. You dont know what ID's you need to set to "No"?

Not applicable

Re: Map Load If Function

Also if you want to use Kourosh's approach use: -

Put this before your load statement

Let v_map = 'ApplyMap('Map_DATASOURCE', THEVALUE)';

Use this in your load statement

if( '$(v_map)' = 'SuperUser', 'No' , '$(v_map)' ) as ENDUSEREDIT;

Community Browser