Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
cancel
Showing results for 
Search instead for 
Did you mean: 
fred_s
Partner - Creator III
Partner - Creator III

Rename fields, value as fieldname

Hi,

I have these two tables, tblmain and tblcodes:

tables.PNG
What I need to achieve is a new table based on the first tables,
where the fieldnames of table 1 (tblmain)  are renamed Myvalue of table 2 (tblcodes).

Anyone?
(example file attached)


Thanks in advance

Labels (1)
1 Solution

Accepted Solutions
swuehl
Champion III
Champion III

Maybe like this:

tblmain:

LOAD * INLINE [

    Profit001, Cost001, Profit002, Cost002

    100, 95, 250, 225

    110, 115, 180, 190

];

tblcodes:

mapping LOAD * INLINE [

    Tblcode, Myvalue

    1, Shop

    2, Sales

];

for i = 1 to NoOfFields('tblmain')

Let vNameOrig = FieldName($(i),'tblmain');

let vNameNew = purgechar('$(vNameOrig)','0123456789') & applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789')));

rename field $(vNameOrig) to $(vNameNew);

next

Hope this helps,

Stefan

edit: If you don't like the CamelCase of your new field names, you could either use

let vNameNew = Capitalize(purgechar('$(vNameOrig)','0123456789') & applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789'))));

or

let vNameNew = purgechar('$(vNameOrig)','0123456789') & lower(applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789'))));

View solution in original post

2 Replies
swuehl
Champion III
Champion III

Maybe like this:

tblmain:

LOAD * INLINE [

    Profit001, Cost001, Profit002, Cost002

    100, 95, 250, 225

    110, 115, 180, 190

];

tblcodes:

mapping LOAD * INLINE [

    Tblcode, Myvalue

    1, Shop

    2, Sales

];

for i = 1 to NoOfFields('tblmain')

Let vNameOrig = FieldName($(i),'tblmain');

let vNameNew = purgechar('$(vNameOrig)','0123456789') & applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789')));

rename field $(vNameOrig) to $(vNameNew);

next

Hope this helps,

Stefan

edit: If you don't like the CamelCase of your new field names, you could either use

let vNameNew = Capitalize(purgechar('$(vNameOrig)','0123456789') & applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789'))));

or

let vNameNew = purgechar('$(vNameOrig)','0123456789') & lower(applymap('tblcodes',num(keepchar('$(vNameOrig)','0123456789'))));

fred_s
Partner - Creator III
Partner - Creator III
Author

Hi swuehl,

Looks like you solved it!
Thanks a lot

Regards,
Fred