I am trying to perform some simple division in a load script but its not working:
Value1/1.2 AS Value2
The server I am on working on is in Spain and their default numeric separators are ',' for decimal and '.' for thousands.
The qvd being loaded in in UK format ( '.' for decimal and ',' for thousands) and i want the output in UK format so in my load scripts i set the defaults to be UK format '.' for decimal and ',' for thousands. But when i do this the Value2 field is blank.
If i set the separators to the default Spanish setting and replace the decimal with a comma in the script it works, even though the 1.2 is in UK format:
REPLACE(Value1,'.',',')/1.2 AS Value2
How can I use UK formatting and get everything to work?
It is accurate to change the format variables to your desired app format, as it makes it easier to generalize the script. The only missing part is to format the loaded data so that it always follows your desired format.
Replace is a string function, which makes the result a text without numerical representation. Unless you are working with actual text values, try using interpretation functions like Num#() and/or Num() to change the look and feel of loaded data.
Num#() enables you to interpret the loaded values as a text and convert it to a number;
Num#(Value1, '#.##0,0', ',', '.')
Notice, Qlik uses dual values, which means that the value will still look like your Spanish format, while it now has a underlying accurate number that enables calculations. Num() enables you to interpret a number and convert it to look like your preferred format. In this case you want to apply the format according to your script variables;
Num(Num#(Value1, '#.##0,0', ',', '.'))
If you have mixed values loaded in the same load statement, you can consider using Alt() as a way to apply the first format that matches your loaded data. This way the statement can handle any defined format regardless of how you alter the script variables;