WHEN and UNLESS

By Barry Harmsen

Mr. ComplainypantsNo, this post isn’t about that negative co-worker or friend who’s always second-guessing your ideas and solutions, it’s about two QlikView script statements that I believe deserve a little more attention: WHEN and UNLESS. (Inspired by Steve Dark’s post on Hidden QlikView Features)

Both statements can be used as an easier, shorter version of the IF-THEN-END IF statement. For example, to set the default value for a variable, but only if it hasn’t been set already:

WHEN ‘$(Variable)’ = ” SET Variable = ‘Value’;

Or, another example, when you’re in a loop and want to add a separator to a concatenated value, unless it’s the last iteration of the loop:

UNLESS $(i) = $(ForMax) LET Variable = ‘$(Variable);’;

One thing you’ll immediately notice when you use these statements is that QlikView syntax highlighting doesn’t seem to recognize them. Don’t worry though, as the attached example application demonstrates, they do really work.

Download the example application