Autonumber() can be considered a lookup function. It takes a passed expression and looks up the value in a lookup table. If the expression value isn't found then it is added to the table and assigned an integer value which is returned. If the expression value is found then it returns the integer value that is assigned against it. Simply put, autonumber() converts each unique expression value into a unique integer value.
Autonumber() is only useful within the QlikView script and has the following syntax:
Autonumber() is only useful within the QlikView script and has the following syntax:
autonumber(expression [, index])
The passed expression can be any string, numeric value or most commonly a field within a loaded table. The passed index is optional and can again be any string or numeric value. For each distinct value within the passed index, QlikView will create a separate lookup table and so the same passed expression values will result in a different returned integer if a different index is specified.
So how exactly are the 3 autonumber functions different? Autonumber() stores the expression value in its lookup table whereas autonumberhash128() stores just the 128bit hash value of the expression value. I'm sure you can guess therefore, autonumberhash256() stores the 256bit hash value expression value.
So how exactly are the 3 autonumber functions different? Autonumber() stores the expression value in its lookup table whereas autonumberhash128() stores just the 128bit hash value of the expression value. I'm sure you can guess therefore, autonumberhash256() stores the 256bit hash value expression value.
Why on earth would I want to use any of these functions? Well the answer is quite simply for efficiency. Key fields between two or more tables in QlikView are most efficient if they contain only consecutive integer values starting from 0. All 3 of the autonumber functions allow you to convert any data value and type into a unique integer value and so using it for key fields allow you to maintain optimum efficiency within your data model.
A final word of warning. All 3 of the autonumber functions have one pitfall, the lookup table(s) exist only whilst the current script execution is active. After the script completes, the lookup table is destroyed and so the same expression value may be assigned different integer values in different script executions. This means that the autonumber functions can't be used for key fields within incremental loads.