1 Reply Latest reply on Oct 8, 2018 3:20 PM by chris mutchler

    ERROR

    wiem bekir

      Hello Guys,

       

      an error in my if else expression,

       

      can you help please

       

      Capture.PNG

       

      IF Datediff('day',[Downtime Start],[Downtime End])=0 Then 

      (IF Datepart('hour',[Downtime End])>19 then 19 else Datepart('hour',[Downtime End]) end)- 

      (IF Datepart('hour',[Downtime Start])<7 then 7 else Datepart('hour',[Downtime Start]) end) 

       

       

       

       

       

       

       

       

      Else 

      Datediff('day',[Downtime Start],[Downtime End])*9 + 

      (IF Datepart('hour',[Downtime End])>19 then 19 else Datepart('hour',[Downtime End]) end)- 

      (IF Datepart('hour',[Downtime Start])<7 then 7 else Datepart('hour',[Downtime Start]) end) 

       

       

       

       

      ELSE

       

       

      if(Datepart('hour',[Downtime End])>19 and Datepart('hour',[Downtime Start])<7) then 'NULL' END

       

       

       

       

      End

       

       

      tHANKS

        • 1. Re: ERROR
          chris mutchler

          Wiem,

          How important is the last bit?

           

          “ELSE

          if(Datepart('hour',[Downtime End])>19 and Datepart('hour',[Downtime Start])<7) then 'NULL' END”

           

          Because that’s what’s causing the error. If, then, else only deals with true or false you’re currently saying is “if my downtime starts on the same day then do this math, however if my downtime does not start on the same day do this other math. Then If my downtime doesn’t start on the same day and my downtime starts on the same day then do this other math.” it’s that last bit that’s causing your error.

           

          Attached is a mock up I made using the superstore data and the corrected if calculated field

           

          Here's the calculated field with out the last bit:

           

          IF Datediff('day',[Order Date],[Ship Date])=0 Then

           

           

          (IF Datepart('hour',[Ship Date])>19 then 19 else Datepart('hour',[Ship Date]) end)-

          (IF Datepart('hour',[Order Date])<7 then 7 else Datepart('hour',[Order Date]) end)

           

           

           

           

          ELSE

          Datediff('day',[Order Date],[Ship Date])*9 +

           

          (IF Datepart('hour',[Order Date])>19 then 19 else Datepart('hour',[Order Date]) end)-

          (IF Datepart('hour',[Ship Date])<7 then 7 else Datepart('hour',[Ship Date]) end)

           

           

          End

           

           

          -chris