Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Escaping nested if statements

Hi all,

I want to make a sum based on two conditions, for example if it is the current month and if the weather is sunny, sum all sales.

What's the best practice and most efficient way of achieving this in Qlikview?

Cheers,

1 Solution

Accepted Solutions
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi David,

One possible approaches is to use Set Analysis. This is far more efficient than If conditions when used in front end expressions.

For example:

sum({$<Month={'$(=Month(Now())'}, Weather={'Sunny'}>} Sales)

Marcus

View solution in original post

5 Replies
marcus_malinow
Partner - Specialist III
Partner - Specialist III

Hi David,

One possible approaches is to use Set Analysis. This is far more efficient than If conditions when used in front end expressions.

For example:

sum({$<Month={'$(=Month(Now())'}, Weather={'Sunny'}>} Sales)

Marcus

Anonymous
Not applicable
Author

There is no need for nesting, it is simply

if(month = current  month AND weather = sunny, expression for true, expression for false)

consenit
Partner - Creator II
Partner - Creator II

Hi there.

I'd favor Set Analysis over IF statements almost any time:

=SUM({$<Wheater={'Sunny'}, Month={$(=MONTH(TODAY()))}>} Sales)

Kind regards,

Ernesto.

richard_chilvers
Specialist
Specialist

David

Is it the case that you might have many combinations of conditions?

For example:

Current Month AND Sunny ...

Current Month AND Raining ....

Current Month AND Windy .....

Last Month AND Was Sunny ....

I agree nested IFs would get messy.

I'd be interested in views. Where appropriate, I try to deal with conditions like this in the script; it can often be handled more elegantly there.

Regards

Not applicable
Author

Thanks all - done a little testing with Set Analysis and I am really impressed. Tidier and performs more efficiently than the IF AND statements.