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: 
giakoum
Partner - Master II
Partner - Master II

sanity check...

Hi all.

I have a table with 5 values, and I need to concatenate those values forming a string. Since I am going to use this string to load from a table, the 5 values actually represent field names so I need to put them into brackets, because there are spaces in the names.

So I thought of looping through the table and construct the string like this :

SET sectionAccessKeyFields='';

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

          LET currentFieldName=FIELDVALUE('KeyField',$(currentFieldNameIndex));

 

          SET sectionAccessKeyFields=$(sectionAccessKeyFields)[$(currentFieldName)];

 

NEXT

The strange thing is that brackets for 1st field seem to just disappear (see red arrows in image) but not for the next 4 fields. I have found a workaround for this, so I need NOT a solution, merely an explanation why this is happening. The workaround I came up with is to start from a non-empty string. but do you have any idea as WHY this is happening? I have attached a file with both the problem and the workaround.

2013-01-23_1124.png

Thank you for your time.

Ioannis.

7 Replies
sujeetsingh
Master III
Master III

I am nat able to get it ??

giakoum
Partner - Master II
Partner - Master II
Author

I am not sure what you mean... you did not understand the problem or...

flipside
Partner - Specialist II
Partner - Specialist II

Hi Ioannis,

It looks like Qlikview is stripping off the square brackets when it picks up the first pass, probably because they are a reserved character in Qlikview language.

You can see this in action ...

SET sectionAccessKeyFields3=[PRODUCT TYPE ID];

SET sectionAccessKeyFields4=[PRODUCT TYPE ID][REGION ID];

SET sectionAccessKeyFields5=$(sectionAccessKeyFields3)[REGION ID];

The middle variable works fine, but the last variable strips off the brackets.

I tend to use LET instead of SET when building strings so as to avoid confusion ...

SET sectionAccessKeyFields=;

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

    LET currentFieldName=FIELDVALUE('KeyField',$(currentFieldNameIndex));

    LET sectionAccessKeyFields='$(sectionAccessKeyFields)' & '[' & '$(currentFieldName)' & ']';

NEXT

flipside

giakoum
Partner - Master II
Partner - Master II
Author

Hi flipside.

Thank you for your answer.

My guess also, brackets being a reserved character, but why does not the same apply to the second and subsequent pass? This is what really troubles me.

Ioannis.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this way

LOAD * INLINE [

    KeyField

    PRODUCT TYPE ID

    REGION ID

    AREA ID

    SUBSALESUNIT ID

    ACCOUNT ID

];

//This makes the brackets for the 1st field disappear

SET sectionAccessKeyFields = '';

FOR currentFieldNameIndex=1 TO FIELDVALUECOUNT('KeyField')

    LET currentFieldName= '[' & FIELDVALUE('KeyField',$(currentFieldNameIndex)) & ']';      

    LET  sectionAccessKeyFields= sectionAccessKeyFields & currentFieldName;   

NEXT

Hope this helps you.

Regards,

Jagan.

giakoum
Partner - Master II
Partner - Master II
Author

Hi Jagan.

thank you but I have found already a similar solution. I just need to know WHY QlikView behaves like this.

Regards,

Ioannis.

jagan
Luminary Alumni
Luminary Alumni

HI,

I think it is evaluation the value for the first time, I am not sure about this.

Regards,

Jagan.