Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
haymarketpaul
Creator III
Creator III

Dynamic Field Renaming

I'm actually using Qlikview but couldn't find my usual forum board.

Not sure it matters though...

Lets say I have a table like this...

BrandCodeEventIDLast Login
ABCEF-12316/10/2020 14:22:37
ABCEF-12326/06/2020 10:41:12

 

I need to rename the Last Login field as below so the field name contains the values from the BrandCode and EventID fields and has a datetime stamp at the end...

BrandCode

EventID

[Last Login] as 'Virtual_Event_Attendee_' & [BrandCode] & '_' & [EventID] & '_Last_Login_' & $(vTodaysDateTime)

 

The BrandCode & EventID will not change

It's ultimately for an export file that will feed into another system where they want a specific fieldname convention.   Future tables of data will have different BrandCodes & EventIDs

Any ideas?

I tried using [...] around the as part too but no luck

vTodaysDateTime is like this...

LET vTodaysDateTime = Timestamp(Now(1),'DD-MMM-YYYY hh:mm:ss');

Labels (1)
1 Solution

Accepted Solutions
Or
MVP
MVP

I don't think you're going to be able to achieve it in the script in the manner which you tried to use, though perhaps other people know ways to get it done. It seems you're trying to determine the column header based on data, but the data isn't read until the column header is determined as I understand it.

I would approach this by using Rename instead:

Load * Inline [
A, B, C
1, A, 100
1, A, 200
];

Let vName = FieldValue('A',1) & FieldValue('B',1) & Timestamp(Now(1),'DD-MMM-YYYY hh:mm:ss');

Rename Field [C] to '$(vName)';

View solution in original post

4 Replies
Or
MVP
MVP

It looks like you're trying to do this at the script level, but you should be doing it at the column level of the object. It should work assuming you indeed have a distinct value in the fields in question (for cleaner reading, I would use Only() for each one).

haymarketpaul
Creator III
Creator III
Author

Thanks for reply

There aren't any objects - after various files are merged to produce that table in the script the data is going to be exported into a file for import into another system.  Hence trying to do it in the script.

Or
MVP
MVP

I don't think you're going to be able to achieve it in the script in the manner which you tried to use, though perhaps other people know ways to get it done. It seems you're trying to determine the column header based on data, but the data isn't read until the column header is determined as I understand it.

I would approach this by using Rename instead:

Load * Inline [
A, B, C
1, A, 100
1, A, 200
];

Let vName = FieldValue('A',1) & FieldValue('B',1) & Timestamp(Now(1),'DD-MMM-YYYY hh:mm:ss');

Rename Field [C] to '$(vName)';

haymarketpaul
Creator III
Creator III
Author

Ah brilliant - works perfectly thank you