Skip to main content
Announcements
Qlik Community Office Hours, March 20th. Former Talend Community users, ask your questions live. SIGN UP
Jennell_McIntire
Employee
Employee

Is there a way to rename several field names in table all at once? This is a question I recently asked myself while building a data model. I was building an app to explore various datasets and one of the source files included a CSV file that had over 300 fields. Most of the fields were codes used to describe a metric. I also had a key or definition table that provided a description for all the codes. Below is a small fictional example of the type of data included in the files.

Data Dictionary file example:

dictionary table.png

 

 

 

 

 

Data file example:

data file table.png

 

The data file was the file that had over 300 codes for the field names. Of course, I can rename fields in the script using “as” in my load script like this:

load as.png

 

 

 

 

 

 

 

This is what I would normally do to rename fields in my data model, but when I have over 300 fields in a single table, this can be cumbersome. I use mapping tables all the time to normalize/update/scramble data in a field, but I did not know mapping tables could be used to also rename fields in a table. Here is the syntax to do this (Qlik Help).

Rename Field (using mapname | oldname to newname{ , oldname to newname })

Rename Fields (using mapname | oldname to newname{ , oldname to newname })

Depending on how many fields you are renaming, you use Rename Field or Rename Fields. One option is to use a map that was previously loaded using the Mapping Load syntax. The other option is to list the old name and new name as parameters in the script function. Since I have a file with all the codes and descriptions, I will use a mapping table in this function. In the script below, I load the data dictionary mapping table named DataDictionaryMap and then I load the Data table.  To keep things simple in this example, the Data table only has 4 fields with code field names, but imagine there are over 300 fields with code field names. The last step is to rename the fields using the Rename Fields function using the DataDictionaryMap I created.

script.png

 

 

 

 

 

 

 

 

 

 

 

A preview of the Data table, as shown below, displays the new field names that use the code description. Instead of renaming each field individually, I used the Rename Fields script function along with a mapping table, to rename all the field names that were included in the map. Fields that are not in the map, remain the same with no change. Note that whenever you rename fields, you want to make sure there are no fields with the same name.

data preview.png

 

It is funny how I have used mapping tables and the rename table function all these years without coming across the rename fields function using a mapping table. Nonetheless, I love it when I learn something new so hopefully, you find this helpful.

Thanks,

Jennell