6 Replies Latest reply on Jan 18, 2017 7:29 AM by BruceRobertson

    IF/Else Statements Help

    bmenendez

      Good Morning,

           trying to do an if/else statement and I keep being told the function can't be found, so i'm doing something wrong...can you help me determine what that is? all appears to look ok but obviously i'm missing something. Basically if there is a number in one field fill in the calculation, or if there is something in the other field fill in the calculation (the user will not fill in both fields, only one or the other).

       

      FMPro Goodness.png

       

      Thanks in advance for your assistance, you are awesome!

        • 1. Re: IF/Else Statements Help
          BruceRobertson

          There is no such statement.

          • 2. Re: IF/Else Statements Help
            Johan Hedman

            Much better  if you do a Case

             

            You should not have ( ) for your If, that is your problem

             

            If(

            Statement ; YourAnswer;

            Otherwise

            )

             

            and for

             

            Case(

            Statement 1; YourAnswer1;

            Statement 1; YourAnswer1;

            Otherwise

            )

            1 of 1 people found this helpful
            • 3. Re: IF/Else Statements Help
              bmenendez

              Thanks so much Johan, that was perfect!!!

              • 4. Re: IF/Else Statements Help
                ErikWegweiser

                bmenendez,

                 

                Let me see if I can restructure it, using the Case function (there is no "If/Else If" function):

                 

                Case(

                estimated_list_price > 0;

                     estimated_list_price - estimated_list_price * discount_percentage / 100;

                discount_percentage > 0;

                     estimated_list_price - estimated_list_price * discount_percentage / 100

                )

                 

                Note 1: Watch your order of operations in the results lines

                Note 2: there could be a 3rd result in the Case statement:

                 

                Case(

                estimated_list_price > 0;

                     estimated_list_price - estimated_list_price * discount_percentage / 100;

                discount_percentage > 0;

                     estimated_list_price - estimated_list_price * discount_percentage / 100;

                    X     // X is whatever value or formula you desire if neither of the first two tests are true.

                )

                • 5. Re: IF/Else Statements Help
                  philmodjunk

                  It would appear that you confused the if FUNCTION with the IF script step here.

                  • 6. Re: IF/Else Statements Help
                    BruceRobertson

                    Note that there are several problems with your IF statement.

                    A way to build the statement using the Case function has been demonstrated; and it is good to know how to do that.

                    But then we move on to some real problems with your underlying logic.

                     

                    1. Numerical comparisons to text strings:

                      estimated_list_price > "0"

                    which should be

                      estimated_list_price > 0

                    (This was corrected in the other replies)

                     

                    2. Logic problems

                    2.a

                    estimated_list_price > 0

                    You included no test for discount at this stage. So it could be empty; 0; or negative.

                     

                    2.b

                    discount_percentage > 0;

                     

                    If the first test didn't apply, this means that estimated_list_price is equal to 0 or less than 0.

                    (Including possibly empty)

                     

                    So you are now working with a negative or empty estimated_list_price.

                    And a positive discount_percentage.

                    Example:

                    -100 - (-100 *25/100)

                     

                    Case(

                    estimated_list_price > 0;

                         estimated_list_price - estimated_list_price * discount_percentage / 100;

                    discount_percentage > 0;

                         estimated_list_price - estimated_list_price * discount_percentage / 100

                    )