Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Set analysis with if condition

Hi All,

      

            I have a below set expression this is Calculates variance of max edition - previous edtion for a  year

$(vpreviousVariance)= pick(($(vSlider))/12,avg({<MaxEdition={1}>}$(v12m)) -

avg({<PreviousEdition={1}>}$(v12m)),avg({<MaxEdition={1}>}$(v24m)) -

avg({<PreviousEdition={1}>}$(v24m)),avg({<MaxEdition={1}>}$(v36m)) -

avg({<PreviousEdition={1}>}$(v36m)),avg({<MaxEdition={1}>}$(v48m)) -

avg({<PreviousEdition={1}>}$(v48m)),avg({<MaxEdition={1}>}$(v60m)) -

avg({<PreviousEdition={1}>}$(v60m)))

I have different  groups(ABC,DEF,XYZ...etc) now i have to extract the variance for each groupfor this am trying to write the if condition for each group like $(vpreviousVariance)= pick(($(vSlider))/12,if(GROUP1='ABC', (avg({<MaxEdition={1}>}$(v12m)) -avg({<PreviousEdition={1}>}$(v12m))),.....rest of the expression.

 

But its giving wrong result. So how can we combine if condition with set analysis here......

21 Replies
Not applicable
Author

   Yes correct, and it will give correct result if we select one value from GROUP1

   v12m: just storing 12 months total sales(it is direct filed from database).

   VX: in this if we select January chart should calculate January- previous year Decemeber month this formula we are storing here

whiteline
Master II
Master II

As an example let's take the first expression:

=avg({$<EditionMonth = {$(#=Only(EditionMonth))}>}$(v12m)) - avg( $(vX)$(v12m) )

To select GROUP1 you should modfy set expressions.

for the first avg its trivial (add GROUP1={'ABC'} as mentioned above).

for the second avg you have to modify vX set expression and also add GROUP1={'ABC'}.

Not applicable
Author

 

vx=If(EditionMonth=1, '{$<ModelYear={$(#=Only(ModelYear)-1)}, EditionMonth={"11"}>}','{$<EditionMonth={"$(=$(vEdn)-2)"}>}')

vedn=EditionMonth

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this

vx=If(EditionMonth=1, '{$<

GROUP1={'ABC'},

ModelYear={$(#=Only(ModelYear)-1)}, EditionMonth={"11"}>}','{$< GROUP1={'ABC'}, EditionMonth={"$(=$(vEdn)-2)"}>}')

Hope this helps you.

Regards,

Jagan.

whiteline
Master II
Master II

As I mentioned above, to calculate the second avg right, you should also add condition GROUP1={'ABC'} in your expression for vx:

vx=If(EditionMonth=1, '{$<ModelYear={$(#=Only(ModelYear)-1)}, EditionMonth={"11"}, GROUP1={'ABC'}>}','{$<EditionMonth={"$(=$(vEdn)-2)"}, GROUP1={'ABC'}>}')

Not applicable
Author

  Still its not working.....any other way to do this

Not applicable
Author

Attached sample app to my orginal post.....please check it

whiteline
Master II
Master II

Why did you say that your group has name 'GROUP1' (and use it in set expressions) when it has name 'Group' ?

Not applicable
Author

its just sample file so i changed it into Group in orginal file it is GROUP1 only 🙂

jagan
Luminary Alumni
Luminary Alumni

Hi Anil,

PFA file.

Regards,

Jagan.