Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
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
Employee
Employee

Re: Change name from one column to another

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
Honored Contributor II

Re: Change name from one column to another

Hi.

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

jason_michaelid
Honored Contributor II

Re: Change name from one column to another

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

Re: Change name from one column to another

Hi,

Try this,

Load A,

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

Load A,

          B

from YourTable;

Hope it help you.

Community Browser