Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

ApplyMap() Degrading in variable

Hi,

I am trying to create a variable that creates several ApplyMap Statements in the Load Script.

In the Second Iteration, it degrades

See below:

 

LET c =Null ();
FOR j =0 to 23

LET c = '$(c)' & If ($(j) =0, '', ', ') & 'ApplyMap'&'('&Chr(39)&'Map_Table'&Chr(39)&','&'%Key1'&'&'&Chr(39)&'|'&Chr(39)&'&'&'[Key2]&'&Chr(39)&'|'&Chr(39)'&'&$(j)&','&'0'&')'&' as [P ($(j))]';
NEXT j

[Table 2]:

LOAD
*,
$(c)

Resident [Table 1] ;

ApplyMap('Map_Table',%Key1&'|'&[Key2]&'|'&0,0) as [P (0)],

ApplyMap(Map_Table,%Key1|[Key2]|1,0) as [P (1)]

// the first iteration is a success.

//the second (and subsequent) iteration(s) is a failure. Note how ' ' for the table name, the & and the '|' have disappeared.

How I could make it behave?

Thanks,


Antoine

PS: it falls within a series of simulation I am performing:

http://community.qlik.com/thread/92181

http://community.qlik.com/thread/91411

1 Solution

Accepted Solutions
pgrenier
Partner - Creator III
Partner - Creator III

Bonjour Antoine,

Reusing a snippet of code from another of your posts related to the same subject, I have added a second instruction that I believe shall build the statement you are wishing for. / En réutilisant un bout de code de l'un de vos autres posts concernant un sujet similaire, je crois bien avoir construit un énoncé qui produira l'effet désiré.

LET b=Null();

LET c=Null();

FOR i=0 to 23

   LET b = '$(b)' & If($(i)=0, '', ',') & '[$(i)] as [Hour $(i)]';

   LET c = '$(c)' & If($(i)=0, '', ',') & 'ApplyMap('& Chr(39) & 'Map_Table' & Chr(39) & ', [%Key1]&' & Chr(39) & '|' & Chr(39) & '&[Key2]&' & Chr(39) & '|' & Chr(39) & '&$(i), 0) as [P ($(i))]';

NEXT i

TRACE $(c);

Regards / Cordialement

Philippe

View solution in original post

4 Replies
rajeshvaswani77
Specialist III
Specialist III

If ($(j) =0 seems to be causing this.

thanks,

Rajesh Vaswani

pgrenier
Partner - Creator III
Partner - Creator III

Bonjour Antoine,

Reusing a snippet of code from another of your posts related to the same subject, I have added a second instruction that I believe shall build the statement you are wishing for. / En réutilisant un bout de code de l'un de vos autres posts concernant un sujet similaire, je crois bien avoir construit un énoncé qui produira l'effet désiré.

LET b=Null();

LET c=Null();

FOR i=0 to 23

   LET b = '$(b)' & If($(i)=0, '', ',') & '[$(i)] as [Hour $(i)]';

   LET c = '$(c)' & If($(i)=0, '', ',') & 'ApplyMap('& Chr(39) & 'Map_Table' & Chr(39) & ', [%Key1]&' & Chr(39) & '|' & Chr(39) & '&[Key2]&' & Chr(39) & '|' & Chr(39) & '&$(i), 0) as [P ($(i))]';

NEXT i

TRACE $(c);

Regards / Cordialement

Philippe

Anonymous
Not applicable
Author

Indeed it is even simpler to put more inside the initial quotes:)

En effet c'est plus simple et astucieux.

It worked like a charm!! Merveilleux et élégant.

Un grand merci !!!

pgrenier
Partner - Creator III
Partner - Creator III

Avec plaisir!