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.
catalyst_75
New Contributor

If..Then.. Renaming fields based off data

I have done some searching and found many post about standard if/then and nested statements. What I could find and was wondering is if I could alias a field based on a different field.

Here is some code that I attempted in the script editor. I know its not right, but I think it get the point and idea of what I am trying to do across.

Is something like this possible? If not, something close? Or do I need to load the data differently to accomplish what I am trying to do?

Thanks,

9 Replies
Not applicable

Re: If..Then.. Renaming fields based off data

You seem to have forgotten to post your code!

MVP
MVP

Re: If..Then.. Renaming fields based off data

for rename field (field, not values) you can search Rename Field in the online help

catalyst_75
New Contributor

Re: If..Then.. Renaming fields based off data

Sorry, could have sworn it was there before hitting post. lol

I had something like this:

If(pat_carrier_type = 'I', pat_carrier_id AS [Conact ID], pat_carrier_id AS [Company ID]);

If(pat_payor_type = 'I', pat_payor_id AS [Conact ID], pat_payor_id AS [Company ID]);

If(pat_tpa_type = 'I', pat_tpa_id AS [Conact ID], pat_tpa_id AS [Company ID]);

MVP
MVP

Re: If..Then.. Renaming fields based off data

Hi Cory,

this will not work. But what would work if you use a variable for the alias or, do a concatenate load where you have different fields depending on the selected data set:

Result:

LOAD

pat_carrier_id AS [Conact ID],

...

From ...

Where pat_carrier_type = 'I';

Concatenate LOAD

pat_carrier_id AS [Company ID],

..

From ...

Where pat_carrier_type <> 'I';

But think this needs to be a litle bit more elaborated..

- Ralf

Not applicable

Re: If..Then.. Renaming fields based off data

Try like this.

example.PNG.png

MVP
MVP

Re: If..Then.. Renaming fields based off data

Good approach although the second expression should be all <>"I".

But what if a combination of fields is true/false (='I' or <>"I")..?

Not applicable

Re: If..Then.. Renaming fields based off data

Thanks Ralf. Can you clarify why the second expression should be <> 'I' rather than = 'I'

MVP
MVP

Re: If..Then.. Renaming fields based off data

..for the else parts:

if(pat_carrier_type = 'I', pat_carrier_id,

  if(pat_payor_type = 'I', pat_payor_id

    if(pat_tpa_type = 'I', pat_tpa_id)))

AS [Conact ID],

if(pat_carrier_type <> 'I', pat_carrier_id,

  if(pat_payor_type <> 'I', pat_payor_id

    if(pat_tpa_type <> 'I', pat_tpa_id)))

AS [Company ID]

Not applicable

Re: If..Then.. Renaming fields based off data

For nested if you should try this once

if(pat_carrier_type = 'I',pat_carrier_id,If(pat_payor_type = 'I',pat_payor_id,If(pat_tpa_type = 'I',pat_tpa_id))) AS [Company ID])

Community Browser