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: 
didierodayo
Partner - Creator III
Partner - Creator III

Dynamic Label name change

Hello,

I don't know if this is possible in Qlik but I like to ask anyway.

I am trying to write a lable expression that I can use to change th

e field name
dynamically inside the table

I have a lot of fields to display and they all have 'OLD_' in front of them.
in the Label box can I write something like =Subfield(getthefield(),'OLD_',2)

so I can just paste it in all the label boxes.

any suggestion is welcomed.

Cheers

1 Solution

Accepted Solutions
adamdavi3s
Master
Master

Just pondering this, you could always reverse this instead of qualifying in the first place, then you can work around the key fields issue.

for example you'd have to run this after each table load to do the 'qualifying', this code assumes your key fields are prefixed 'KEY'

Load table1 blah;

Let vTableName = TableName(table1);

For f = 1 to NoOfFields('$(vTableName)')

    let vFieldOld = FieldName($(f),'$(vTableName)');

    let vFieldNew = '$(vTableName).$(vFieldOld)';

    if(left('$(f)',3)<>'KEY') then

    RENAME FIELD $(vFieldOld) to $(vFieldNew);

    else

    endif;

   

Next f;

Then at the end just run the original script:

For vTable = 0 to NoOfTables() -1

  Let vTableName = TableName(vTable);

For f = 1 to NoOfFields('$(vTableName)')

    let vFieldOld = FieldName($(f),'$(vTableName)');

    let vFieldNew = Replace('$(vFieldOld)','$(vTableName)'&'.','');

    if(left('$(f)',3)<>'KEY') then

    RENAME FIELD $(vFieldOld) to $(vFieldNew);

    else

    endif;

   

Next f;

Next ;

View solution in original post

10 Replies
Anil_Babu_Samineni

That is possible when you try something like below

=SubField('Old_Item','_',-1) //Here, this is complex and kills the performance. Why not simply Item on label. Any problem over here

In fact, This is very typical to write for all Dimensions, I would love to use Script level using Preceding load via All field to single field

Please add me Anil_Babu_Samineni to interact faster when reply back. Speak low think High.

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
jonathandienst
Partner - Champion III
Partner - Champion III

Although you can apply labels to field names, I don't think it is possible  to do it the way you suggest. It is fairly easy to rename the fields in the load script. Build a mapping table of the old and new names (fo example, in a spreadsheet), load this mapping and use the rename option Rename Fields Using MapTable.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
didierodayo
Partner - Creator III
Partner - Creator III
Author

Hi Jonathan. 

Reason I am not using the applymap is because I am getting the field names after Using Qualify  on multiple qvd load.

These are big tables so it takes awhile to rename the fields manually.

Can we applymap after Qualify *; ?

What is the best ways to rename fields back to their filebasename after Using Applymap?

Thanks

didierodayo
Partner - Creator III
Partner - Creator III
Author

Hi Anil ,

I need something generic that could be applied to all the dimensions because I have many of them .

I think it is not possible at this stage.

I will try the apply map suggested by Jonathan.

Thanks

adamdavi3s
Master
Master

Hi Didier,

I wrote a little script to do this in the load script, the only thing you have to remember is that you can not rename key fields

For vTable = 0 to NoOfTables() -1

   Let vTableName = TableName(vTable);

For f = 1 to NoOfFields('$(vTableName)')

    let vFieldOld = FieldName($(f),'$(vTableName)');

    let vFieldNew = Replace('$(vFieldOld)','$(vTableName)'&'.','');

     RENAME FIELD $(vFieldOld) to $(vFieldNew);

Next f;

Next ;

didierodayo
Partner - Creator III
Partner - Creator III
Author

Thanks Adam I'll give this a shot.

adamdavi3s
Master
Master

Just pondering this, you could always reverse this instead of qualifying in the first place, then you can work around the key fields issue.

for example you'd have to run this after each table load to do the 'qualifying', this code assumes your key fields are prefixed 'KEY'

Load table1 blah;

Let vTableName = TableName(table1);

For f = 1 to NoOfFields('$(vTableName)')

    let vFieldOld = FieldName($(f),'$(vTableName)');

    let vFieldNew = '$(vTableName).$(vFieldOld)';

    if(left('$(f)',3)<>'KEY') then

    RENAME FIELD $(vFieldOld) to $(vFieldNew);

    else

    endif;

   

Next f;

Then at the end just run the original script:

For vTable = 0 to NoOfTables() -1

  Let vTableName = TableName(vTable);

For f = 1 to NoOfFields('$(vTableName)')

    let vFieldOld = FieldName($(f),'$(vTableName)');

    let vFieldNew = Replace('$(vFieldOld)','$(vTableName)'&'.','');

    if(left('$(f)',3)<>'KEY') then

    RENAME FIELD $(vFieldOld) to $(vFieldNew);

    else

    endif;

   

Next f;

Next ;

didierodayo
Partner - Creator III
Partner - Creator III
Author

Thanks a lot Adam this second suggestion works my scenario.

eromiyasimon
Creator II
Creator II

'OLD_' &''&  'Field_name'