6 Replies Latest reply: Oct 31, 2014 10:05 AM by Aaron Morgan RSS

    if statement within an if statement

      Im trying to write an if statement so that if my data is of a certain value then the background turns a certain colour, this will then change depending on which conditions are picked by a slider.

       

      I've set up the variables and the various values but am having trouble wrapping an if statement within another if statement,

       

      my code looks like

       

      if(vKickOutcomeMatchTable=0)

       

       

      if([Positive %]/[Count({SAR_1<[Kick Outcome]={1}>}TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)/Count({SAR_1} TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)])>$(vT1),$(vRAG1),
      if([
      Positive %]/[Count({SAR_1<[Kick Outcome]={1}>}TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)/Count({SAR_1} TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)])>$(vT2),$(vRAG2),
      if([
      Positive %]/[Count({SAR_1<[Kick Outcome]={1}>}TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)/Count({SAR_1} TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)])>$(vT3),$(vRAG3),
      if([
      Positive %]/[Count({SAR_1<[Kick Outcome]={1}>}TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)/Count({SAR_1} TOTAL <Kicker> DISTINCT MatchID_ScenarioMap)])>$(vT4),$(vRAG4))

       

      if(vKickOutcomeMatchTable=1)

      if([Positive %]/[({SAR_1<[Kick Outcome]={1}>}TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)/Count({SAR_1<[Kick Outcome]={'-1',0,1>} TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)])>$(vT1),$(vRAG1),

      if([Positive %]/[({SAR_1<[Kick Outcome]={1}>}TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)/Count({SAR_1<[Kick Outcome]={'-1',0,1>} TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)])>$(vT2),$(vRAG2),

      if([Positive %]/[({SAR_1<[Kick Outcome]={1}>}TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)/Count({SAR_1<[Kick Outcome]={'-1',0,1>} TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)])>$(vT3),$(vRAG3),

      if([Positive %]/[({SAR_1<[Kick Outcome]={1}>}TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)/Count({SAR_1<[Kick Outcome]={'-1',0,1>} TOTAL <MatchID> DISTINCT MatchID_ScenarioMap)])>$(vT4),$(vRAG4),

       

       

      This is my first time working with if statements within another if statement so would really appreciate any help to make this code work!

       

        • Re: if statement within an if statement
          Alessandro Saccone

          It seems that the problem are unbalanced parenthesys, (the closing ones)

           

          Follow this syntax:

           

          If(cond1=true, 'X',

          If(cond2=true, 'Y',

          'Z'

          )

          )

          • Re: if statement within an if statement
            Jonathan Poole

            The basic format is    IF(  CONDITION ,  TRUE EXPRESSION , FALSE EXPRESSION)

             

            If you want to wrap an existing expression , conditional or otherwise,  you need to figure out if the existing expression is the TRUE or FALSE expression for the new condition

             

            Either

             

            if(   CONDITION ,    EXISTING STATEMENT ,   FALSE EXPRESSION)

             

            or

             

            if(   CONDITION ,   TRUE EXPRESSION,   EXISTING STATEMENT )

            • Re: if statement within an if statement
              Aaron Morgan

              Hi Rob,


              A few things you need to watch out for!

               

              1. If(vKickOutcomeMatchTable=0) - You don't want the end bracket here as it's closing your If statement, so get rid of it.

               

              2. Inside your statements you are doing 3 divisions, but I don't think you've wrapped the expression you want calculated first in brackets. If you want to divide "Positive %" field by your expression to calculate the average, you'll want to precede the [Count...] statement with a bracket and end it with a bracket after the second ScenarioMap statement.

               

              3. As a rule of thumb, for every extra if statement you nest, you'll need an extra closing bracket when you reach the end, so if you haven't got the 4 closing brackets if you've got 4 if statements, you know you're in trouble - but use the syntax checker and this should tell you where you're going wrong, if you highlight an end bracket it will show you the bracket it's "closing" and so you should be able to see if you've missed any (not to mention it'll be highlighted red).

               

              It may also be worth replacing your long expression with a variable that stores your expression, as this may help you to see where you're going wrong and reduce the size of the total expression!

               

              Regards.