Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Expression

Hi all,

I got this expression:

If(isnull((SUM({$< Year = {$(=(max(Year)))} >} RevenueAmount))/(SUM({$< Year = {$(=(max(Year)-1))} >} RevenueAmount))-1), 0, (SUM({$< Year = {$(=(max(Year)))} >} RevenueAmount))/(SUM({$< Year = {$(=(max(Year)-1))} >} RevenueAmount))-1)

However now I got my formula twice. Because the first part says if it's null you have to value it with 0. Then if it's not null it has to calculate the formula again.  This will probably effect my system capacity so I thinking is there an other way to solve this?

kind regards

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Use Alt():

=Alt(((SUM({$< Year = {$(=(max(Year)))} >} RevenueAmount)) / (SUM({$< Year = {$(=(max(Year)-1))} >} RevenueAmount))) - 1, 0)

Alt() will return the first parameter (your expression) if it is not null*, otherwise returns the second.

HTH

Jonathan

*actually if it is not numeric, but a null is non-numeric so it works in this case

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Use Alt():

=Alt(((SUM({$< Year = {$(=(max(Year)))} >} RevenueAmount)) / (SUM({$< Year = {$(=(max(Year)-1))} >} RevenueAmount))) - 1, 0)

Alt() will return the first parameter (your expression) if it is not null*, otherwise returns the second.

HTH

Jonathan

*actually if it is not numeric, but a null is non-numeric so it works in this case

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
its_anandrjs

Another way you can use variables for this like

if(Isnull($(YourExpression),0 ,$(YourExpression))

Hope this helps

Thanks & Regards

tresesco
MVP
MVP

Try with alt(), like:

=Alt(yourExpression_once, 0)

Note: The alt function returns the first of the parameters that has a valid number representation. If no such match is found, the last parameter will be returned. Any number of parameters can be used.

Or, use you can use variable instead of direct expression. Using variable twice would not recalculate unlike you are afraid of performance.