6 Replies Latest reply on Nov 18, 2015 10:32 AM by ch0c0halic

    I am trying to nest an if statement using 2 parameters

    Jwaldridge

      I am trying to use a nested if statment using 2 parameters.  But it does not seem to do the nested if statement

       

      If ( Total Overtime Hours = "Yes" ; 0 ; If ( LUNCH = "Yes" ; Mod (Tiem out - Tiem in + 86400 - 1600; 86400) ; Mod (Tiem out - Tiem in + 86400; 86400) ) )

       

      I have the following fields

      total hours (this is where the code is calculated)

      Total Overtime hours

      Lunch

      Overtime Results

      Time in (I know I can't Spell)

      Time out

       

      would like this calculation to result in the total hours =

      0 if Total Overtime Hours is "Yes"

      total time - 30 min  if total overtime hours is blank and Lunch = "Yes"

      total time  if total overtime hours is blank and lung is black.

       

      The OTR is Yes I get a 0 but nothing after that.  If I do just the nested if statement it works switching the Lunch from Yes to blank.

       

      Any suggestions

        • 1. Re: I am trying to nest an if statement using 2 parameters
          jbrown

          Morning.

          I would use a case statement. Cases are, in my opinion, easier to read. The FM calc engine runs through the list until it finds the first one that is true and then stops. It returns the result of the true line (the 2nd parameter in each line).

           

          Case(

               Total Overtime Hours = "Yes" ; 0;

               LUNCH = "Yes" and IsEmpty (Total Overtime Hours ) ; Mod (Tiem out - Tiem in + 86400 - 1600; 86400) ;

               IsEmpty ( Total Overtime Hours ) AND IsEmpty (LUNCH) ; Mod (Tiem out - Tiem in + 86400; 86400)

          )    


          I took these directly from your calc result desire, described below.

           

          The case statement is more descriptive to view.

           

          The OTR is Yes I get a 0 but nothing after that.  If I do just the nested if statement it works switching the Lunch from Yes to blank.

          I'm not quite sure what this means here. the IF statement would stop calculating if Total OverTimeHours = 0.

          • 2. Re: I am trying to nest an if statement using 2 parameters
            coherentkris

            A properly written If .. Else statement is just as valid as a case.

            Sometimes its easier to see what you have if you indent/nest for readability and use commments.

             

            If ( Total Overtime Hours = "Yes" ; // outer if test

                 0 ; // outer if true result and calculation proceeds directly to close outer if

                 If ( LUNCH = "Yes" ; //inner if test

                           Mod (Tiem out - Tiem in + 86400 - 1600; 86400) ; // inner if test = true result

                           Mod (Tiem out - Tiem in + 86400; 86400) // inner if test = false result

                      ) // close inner if

            ) // close outer if

             

            My only question is what exactly do you want this line to do...

            Mod (Tiem out - Tiem in + 86400 - 1600; 86400)

             

            What happens if Tiem out is less than Tiem in?

            • 3. Re: I am trying to nest an if statement using 2 parameters
              jwaldridge

              The Case Option did not work in my situation but the nested if statements by coherent kris worked great.  Thanks.  Not sure how to change the status to Answered.  Any Suggestions?

              • 4. Re: I am trying to nest an if statement using 2 parameters
                coherentkris

                This...

                If ( Total Overtime Hours = "Yes" ; 0 ; If ( LUNCH = "Yes" ; Mod (Tiem out - Tiem in + 86400 - 1600; 86400) ; Mod (Tiem out - Tiem in + 86400; 86400) ) )


                is exactly the same as ..


                If ( Total Overtime Hours = "Yes" ; // outer if test

                     0 ; // outer if true result and calculation proceeds directly to close outer if

                     If ( LUNCH = "Yes" ; //inner if test

                               Mod (Tiem out - Tiem in + 86400 - 1600; 86400) ; // inner if test = true result

                               Mod (Tiem out - Tiem in + 86400; 86400) // inner if test = false result

                          ) // close inner if

                ) // close outer if

                 

                 

                with all the comments and indents removed.

                Either version return:

                Total Overtime Hours = "Yes" returns 0 and stop.

                Total Overtime Hours not "Yes" then...

                     If LUNCH is "Yes" return calc 1 and stop

                     if LUNCH not "Yes" return calc 2 and stop.

                 

                 

                you said "The OTR is Yes I get a 0 but nothing after that". What did you expect "after that"? and what exactly does OTR mean in the context of this question? If you want precise answers you have got to ask precise questions.

                • 5. Re: I am trying to nest an if statement using 2 parameters
                  jwaldridge

                  Sorry it should have said OTH for Total overtime hour.

                   

                  When i first coded it it would return a result of 0 the overtime hours were "yes" but if it was "no" or blank it did not do the calculation.  I copied and pasted your code and removed the comments and it worked correctly so I must have missed something in the code before.  I appreciate you time.  i would like to mark this as answered as you have answered my question but  i am new so i am not sure how to do that, 

                  • 6. Re: I am trying to nest an if statement using 2 parameters
                    ch0c0halic

                    Jeremy,

                     

                    In order to Mark the Correct answer you must log in with your Account. If you are using Guest access to review the Discussion you don't see the "Mark Answer Correct" button.