Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I will be using code that might have slight syntactic errors, but I hope it will be sufficient to express my question.
If in some expression I use SUM(fieldname*5+2), the formula inside the parenthesis must obviously be evaluated for each fieldname value.
I guess this is the same in the case of SUM(if(fieldname<5,fieldname*3,fieldname/5)).
However, a variable has a constant value throughout all the data. So, one question is if the following: Will
SUM(if(varname<5,fieldnameA,fieldnameB))
be evaluated for each A-B combination, or is qlikview smart enough to evaluate the if condition once and then replace it by whichever field the condition leads to?
If the answer is "unfortunately, no", how about the following:
SUM(&(varname))
where in the script I have:
set varname=if(varname<5,'fieldnameA','fieldnameB')
Will this be evaluated once, as the formula text is not resolved from the start?
I hope, and believe, this must be "yes", since else how would qv know for what data combinations it would have to evaluate the final expression?
If I have been vague or there is any way to improve this post, please let me know and have a chance to make it right!
The variable evaluation might not happen row-wise (based on it's definition), however, the check of TRUE/FALSE in IF clause would get evaluated row-wise. Instead, for such case the below structure would be a winner may be:
If( variable<5, Sum(FieldA), Sum(FieldB))
Or, may be like second way you have shown.
Not full sure I understand where you are using this, but AFAIK anytime you use an if statement (through a variable or directly) it will be evaluated on row by row basis and it will evaluate both the true and false condition before it displays the output for either of the condition.
The variable evaluation might not happen row-wise (based on it's definition), however, the check of TRUE/FALSE in IF clause would get evaluated row-wise. Instead, for such case the below structure would be a winner may be:
If( variable<5, Sum(FieldA), Sum(FieldB))
Or, may be like second way you have shown.