Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Expression.Error in nested "if" statements

Hi all,   I am at a bit of a loss here and need your help. I've been trying to write a fairly complex function in M and keep getting stuck at a point here.   Main target is to use a bunch of par...
  • Nolock's avatar
    7 years ago

    Hi Anonymous,

    remove the part with "ServiceTime =" before empty duration. 

     

    (StartDate as datetime, EndDate as datetime) as duration =>
    let
    	<variable declaration>	
    	ServiceTime = if (
    		<statement that returns "false" if the ServiceTime needs to be calculated>	) then (
    		ServiceTime = #duration(0,0,0,0)

     

    Next point is

    #duration(C_ServiceTimeInDays - C_StartDateIsWorkDay - C_EndDateIsWorkDay) 

    which is definitely not correct, just use C_ServiceTimeInDays - C_StartDateIsWorkDay - C_EndDateIsWorkDay.

     

    Btw. a similar task has been solved in Date / Time difference excluding weekends and factoring working ours, you can also inspire also there.