Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Change name from one column to another

Hello, i am new in this and i have a problem that for sure would be very easy to solve it.

If i have to columns with different data. For example:

I want to change just the ones that are named Web in the column A to Web in the Column B

1) 2)
AB AB
CCMurcia CCMurcia
WebAndalucia WebWeb
DirectCataluña DirectCataluña
WebMadrid WebWeb
CCMurcia CCMurcia
DirectAsturias DirectAsturias

It is that possible?

Thanks


4 Replies
Andrea_Ghirardello

Try the following script:

SecondTable:

load
     
A as _A,
     
if(A = 'Web', A,B) as _B
resident FirstTable;

drop table FirstTable;

rename field _A to A;

rename field _B to B;

rename table SecondTable to FirstTable;

whiteline
Master II
Master II

Hi.

It's possible. You can do it easily in script or at front-end.

Jason_Michaelides
Luminary Alumni
Luminary Alumni

The most flexible way to achieve this is by using a mapping table. If() statements are fine as long as the code never needs to change, but what if you decide in the future that 'CC' should change to 'Web' as well?

Let's assume you have an Excel spreadsheet that contains the values in field A that should be changed and what they should change to. E.g.:

FieldAFieldB
WebWeb
NetFish
RabbitTasty

In your QV script, load this as a mapping tbale:

Map_FieldB:

MAPPING LOAD
     FieldA,

     FieldB

FROM....MappingSpreadsheet...;

Then, when loading your data, refer to this mapping table using ApplyMap() with FieldB as the third parameter so that for all FieldA values not in the mapping table, the original value of FieldB will be returned:

Data:

LOAD

     FieldA,

     ApplyMap('Map_FieldB',FieldA,FieldB)     AS     FieldB

FROM....;

Hope this helps,

Jason

Not applicable
Author

Hi,

Try this,

Load A,

     If(A='Web',A,B) AS B;

Load A,

          B

from YourTable;

Hope it help you.