Summary: I explain the mystery of why sometimes script fieldname changes flow through to expressions and sometimes not.
When adding a new field to an existing Qlik Script Load statement, where do you insert the new field in the field list? Top, bottom, alphabetically?
Where you insert the new field can break existing chart expressions — if you also rename fields using “as”. Let’s look at an example. We have an existing KPI using the expression “Sum(Sales)”.

If we modify our script to rename field [Sales] to [Total Sales]

Qlik will “automagically” update the field name in our KPI expression. Great!

What if we make the script change like this?


Our KPI is broken! No automagic! Why?
The System fields $Table, $Field, $FieldNo provide us a clue. “Sales” is the nth ordinal field in table “Orders”.

Automagic fix-up depends on the $FieldNo remaining constant. Inserting or deleting a field in the Load statement may change the $FieldNo. That’s when things break.

To avoid breaking existing expressions, follow these practices:
- Don’t rename and restructure script in the same reload. A limited load of one row is enough to do rename fix-ups.
- If in doubt, add new fields to the end of your LOAD statement.
- Use QSDA Pro to audit for broken measures.
-Rob
Still time to register for the Masters Summit for Qlik Cloud in Vienna 30 Sept – 02 Oct. We’ll be training on all things Qlik Cloud as well as favorite topics in scripting, set analysis, performance tuning and integration. See the agenda here.