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

Nested if condition in expressions

Hi,

I am trying to accomplish a nested if condition to an expression but i am not able to successfully implement it. I am comparing a sales trend, and my expression is given below,

if(((Sum({$<Year = {$(=Only(Year ))}>}[Net Sales])) - (Sum({$<Year  = {$(=Only(Year)-1)}>}[Net Sales]))) = 0,'qmem://<bundled>/BuiltIn/arrow_e_y.png', if(((Sum({$<Year  = {$(=Only(Year ))}>}[Net Sales])) - (Sum({$<Year  = {$(=Only(Year )-1)}>}[Net Sales]))) > 0,'qmem://<bundled>/BuiltIn/arrow_n_g.png','qmem://<bundled>/BuiltIn/arrow_s_r.png')

I am trying to implement image to this expression. characters starting with "gmem" are nothing but the link to images. If I use a single if condition, it works perfectly fine. But if I want to have three possibilities (using 2 if conditions), then it is not working. Please help.


Thanks,

Sivacharan

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Perhaps a parenthesis issue. Put one more closing parenthesis at the end and try.

View solution in original post

9 Replies
tresesco
MVP
MVP

Perhaps a parenthesis issue. Put one more closing parenthesis at the end and try.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Check this

if(Sum({$<Year = {$(=Max(Year))}>}[Net Sales]) - Sum({$<Year  = {$(=Max(Year)-1)}>}[Net Sales]) =  0, 'qmem://<bundled>/BuiltIn/arrow_e_y.png',

if(Sum({$<Year  = {$(=Max(Year ))}>}[Net Sales]) - Sum({$<Year  = {$(=Max(Year)-1)}>}[Net Sales]) > 0, 'qmem://<bundled>/BuiltIn/arrow_n_g.png','qmem://<bundled>/BuiltIn/arrow_s_r.png'))

Hope this helps you.

Regards,

jagan.

Not applicable
Author

Hi

Thanks for the quick reply.

I Actually want to calculate the sum for the currently selected year - previous year . like if I select year 2009, then it should calculate for sales of 2009 - sales of 2008 or vice versa. Believe max won't work the way I want..

jagan
Luminary Alumni
Luminary Alumni

Hi,

I you select 2009, then Max(Year) is 2009 and Max(Year) -1 is 2008, this is what I am doing, if you do not give Max() and use Only(), you will get null value when no year is selected.  That is why I used Max(), if Year is always selected one then you can use Only().


Is above expression working?  Did you checked?


Hope this helps you.

Regards,

Jagan.

d_pranskus
Partner - Creator III
Partner - Creator III

Hi

I would suggest to use the following expression

=PICK(SIGN(SUM({$<Year = {$(=Max(Year))}>}[Net Sales]) - SUM({$<Year  = {$(=Max(Year)-1)}>}[Net Sales])) + 2, 'qmem://<bundled>/BuiltIn/arrow_s_r.png', 'qmem://<bundled>/BuiltIn/arrow_e_y.png', 'qmem://<bundled>/BuiltIn/arrow_n_g.png')

Anonymous
Not applicable
Author

if(Sum({$<Year = {$(=Only(Year ))}>}[Net Sales]) - Sum({$<Year  = {$(=Only(Year)-1)}>}[Net Sales]) = 0,'qmem://<bundled>/BuiltIn/arrow_e_y.png',

   if(Sum({$<Year  = {$(=Only(Year ))}>}[Net Sales]) - Sum({$<Year  = {$(=Only(Year )-1)}>}[Net Sales]) > 0,'qmem://<bundled>/BuiltIn/arrow_n_g.png','qmem://<bundled>/BuiltIn/arrow_s_r.png'))

Not applicable
Author

Thanks for pitching in the issue with my expression.. Adding the parenthesis at the end did work..  So dumb of me

Not applicable
Author

Yep, it does work. I missed the parenthesis at the end.. Max also works fine.. However, I have a condition to display the column only if there is one selection is made.. But this is a good learning to display the max selection when I dont use that condition.. Thanks

Not applicable
Author

This too does work. Thanks