Stopping code once a @if is true in Column formula

I need the following formula to stop once one of the @if statements is true. The formula is within a column. Thanks for any help. If you have any other suggestions, feel free to pass it on.

@If( @Weekday(@Today)=1;@If(@Contains(@RightBack(RouteCode;“-”);“SU”);“1”;@Contains(@RightBack(RouteCode;“-”);“M”);“2”;@Contains(@RightBack(RouteCode;“-”);“TU”);“3”;@Contains(@RightBack(RouteCode;“-”);“W”);“4”;@Contains(@RightBack(RouteCode;“-”);“TH”);“5”;@Contains(@RightBack(RouteCode;“-”);“F”);“6”;@Contains(@RightBack(RouteCode;“-”);“SA”);“7”;“8”);“”);

@If( @Weekday(@Today)=2;@If(@Contains(@RightBack(RouteCode;“-”);“M”);“1”;@Contains(@RightBack(RouteCode;“-”);“TU”);“2”;@Contains(@RightBack(RouteCode;“-”);“W”);“3”;@Contains(@RightBack(RouteCode;“-”);“TH”);“4”;@Contains(@RightBack(RouteCode;“-”);“F”);“5”;@Contains(@RightBack(RouteCode;“-”);“SA”);“6”;@Contains(@RightBack(RouteCode;“-”);“SU”);“7”;“8”);“”);

@If( @Weekday(@Today)=3;@If(@Contains(@RightBack(RouteCode;“-”);“TU”);“1”;@Contains(@RightBack(RouteCode;“-”);“W”);“2”;@Contains(@RightBack(RouteCode;“-”);“TH”);“3”;@Contains(@RightBack(RouteCode;“-”);“F”);“4”;@Contains(@RightBack(RouteCode;“-”);“SA”);“5”;@Contains(@RightBack(RouteCode;“-”);“SU”);“6”;@Contains(@RightBack(RouteCode;“-”);“M”);“7”;“8”);“”);

@If( @Weekday(@Today)=4;@If(@Contains(@RightBack(RouteCode;“-”);“W”);“1”;@Contains(@RightBack(RouteCode;“-”);“TH”);“2”;@Contains(@RightBack(RouteCode;“-”);“F”);“3”;@Contains(@RightBack(RouteCode;“-”);“SA”);“4”;@Contains(@RightBack(RouteCode;“-”);“SU”);“5”;@Contains(@RightBack(RouteCode;“-”);“M”);“6”;@Contains(@RightBack(RouteCode;“-”);“TU”);“7”;“8”);“”);

@If( @Weekday(@Today)=5;@If(@Contains(@RightBack(RouteCode;“-”);“TH”);“1”;@Contains(@RightBack(RouteCode;“-”);“F”);“2”;@Contains(@RightBack(RouteCode;“-”);“SA”);“3”;@Contains(@RightBack(RouteCode;“-”);“SU”);“4”;@Contains(@RightBack(RouteCode;“-”);“M”);“5”;@Contains(@RightBack(RouteCode;“-”);“TU”);“6”;@Contains(@RightBack(RouteCode;“-”);“W”);“7”;“8”);“”);

@If( @Weekday(@Today)=6;@If(@Contains(@RightBack(RouteCode;“-”);“F”);“1”;@Contains(@RightBack(RouteCode;“-”);“SA”);“2”;@Contains(@RightBack(RouteCode;“-”);“SU”);“3”;@Contains(@RightBack(RouteCode;“-”);“M”);“4”;@Contains(@RightBack(RouteCode;“-”);“TU”);“5”;@Contains(@RightBack(RouteCode;“-”);“W”);“6”;@Contains(@RightBack(RouteCode;“-”);“TH”);“7”;“8”);“”);

@If( @Weekday(@Today)=7;@If(@Contains(@RightBack(RouteCode;“-”);“SA”);“1”;@Contains(@RightBack(RouteCode;“-”);“SU”);“2”;@Contains(@RightBack(RouteCode;“-”);“M”);“3”;@Contains(@RightBack(RouteCode;“-”);“TU”);“4”;@Contains(@RightBack(RouteCode;“-”);“W”);“5”;@Contains(@RightBack(RouteCode;“-”);“TH”);“6”;@Contains(@RightBack(RouteCode;“-”);“F”);“7”;“8”);“”)

Subject: Stopping code once a @if is true in Column formula

I think you can use @Return() to stop executing.

Subject: Stopping code once a @if is true in Column formula

Hi John.

Rather than exiting out early, you should use the full use of the @If, although it would be fairly ugly.

Just remember that the @If functions works like:

@If(expression; true; false)

So, on the first line, instead of ending it with a “”, start the next else expression of the @If.

By the way, what your doing is very longhand, and you’re making the server do a whole lot of work. A much simpler expression would be:

vDays:=“SU”:“M”:“TU”:“W”:“TH”:“F”:“SA”;

vWD:=@Weekday(@Today);

vRtDay:=@Member(@RightBack(RouteCode; “-”); vDays);

vDay:=vRtDay-vWD +1;

@If(vDay < 1; 7 + vDay; vDay)

Of course, that only will work if your @RightBack function returns ONLY the day character code. I noticed you have @Contains, so if your @RightBack doesn’t return a day code (SU, M, T, etc) by itself, that won’t work.

  • Steve

Subject: LOOK AT JAMES’ SUGGESTION…IT IS MORE EFFICIENT

Your current formula may not be the best way to go about it strategically…James’ solution would probably even speed up the view’s display.

I am curious if the RoutCode has whole names of days to the right of the dash (SUNDAY, MONDAY, etc.).

Here is a slight tweak to Jame’s formula, where the notion of putting an “8” is taken out, and the @If’s inside are lined up by days, so the pattern of the results is easier to read to someone doing maintenance.

====================

_DayCode := @RightBack(RouteCode;“-”);

_Mon := @Contains(_DayCode;“M”);

_Tues := @Contains(_DayCode;“TU”);

_Wed := @Contains(_DayCode;“W”);

_Thurs := @Contains(_DayCode;“TH”);

_Fri := @Contains(_DayCode;“F”);

_Sat := @Contains(_DayCode;“SA”);

_Sun := @Contains(_DayCode;“SU”);

_Wkday := @Weekday(@Today);

@If(

_Wkday=1; @If( _Sun; “1”; _Mon; “2”; _Tues; “3”; _Wed; “4”; _Thurs; “5”; _Fri; “6”; _Sat; “7”; “”);

_Wkday=2; @If( _Sun; “7”; _Mon; “1”; _Tues; “2”; _Wed; “3”; _Thurs; “4”; _Fri; “5”; _Sat; “6”; “”);

_Wkday=3; @If( _Sun; “6”; _Mon; “7”; _Tues; “1”; _Wed; “2”; _Thurs; “3”; _Fri; “4”; _Sat; “5”; “”);

_Wkday=4; @If( _Sun; “5”; _Mon; “6”; _Tues; “7”; _Wed; “1”; _Thurs; “2”; _Fri; “3”; _Sat; “4”; “”);

_Wkday=5; @If( _Sun; “4”; _Mon; “5”; _Tues; “6”; _Wed; “7”; _Thurs; “1”; _Fri; “2”; _Sat; “3”; “”);

_Wkday=6; @If( _Sun; “3”; _Mon; “4”; _Tues; “5”; _Wed; “6”; _Thurs; “7”; _Fri; “1”; _Sat; “2”; “”);

_Wkday=7; @If( _Sun; “2”; _Mon; “3”; _Tues; “4”; _Wed; “5”; _Thurs; “6”; _Fri; “7”; _Sat; “1”; “”);

“”)

Subject: Stopping code once a @if is true in Column formula

I’d use the @If itself to stop the code from executing further which means I’d not use 7 separate @If statements. Instead I’d try and use a single @If statement (and use temporary variables - especially since it’s in a view) as follows:

T1:=@Weekday(@Today);

T2:=@RightBack(RouteCode;“-”);

@If(

T1=1&@Contains(T2;“SU”);“1”;T1=1&@Contains(T2;“M”);“2”;T1=1&@Contains(T2;“TU”);“3”;T1=1&@Contains(T2;“W”);“4”;T1=1&@Contains(T2;“TH”);“5”;T1=1&@Contains(T2;“F”);“6”;T1=1&@Contains(T2;“SA”);“7”;T1=1;“8”;

T1=2&@Contains(T2;“M”);“1”;T1=2&@Contains(T2;“TU”);“2”;T1=2&@Contains(T2;“W”);“3”;T1=2&@Contains(T2;“TH”);“4”;T1=2&@Contains(T2;“F”);“5”;T1=2&@Contains(T2;“SA”);“6”;T1=2&@Contains(T2;“SU”);“7”;T1=2;“8”;

T1=3&@Contains(T2;“TU”);“1”;T1=3&@Contains(T2;“W”);“2”;T1=3&@Contains(T2;“TH”);“3”;T1=3&@Contains(T2;“F”);“4”;T1=3&@Contains(T2;“SA”);“5”;T1=3&@Contains(T2;“SU”);“6”;T1=3&@Contains(T2;“M”);“7”;T1=3;“8”;

T1=4&@Contains(T2;“W”);“1”;T1=4&@Contains(T2;“TH”);“2”;T1=4&@Contains(T2;“F”);“3”;T1=4&@Contains(T2;“SA”);“4”;T1=4&@Contains(T2;“SU”);“5”;T1=4&@Contains(T2;“M”);“6”;T1=4&@Contains(T2;“TU”);“7”;T1=4;“8”;

T1=5&@Contains(T2;“TH”);“1”;T1=5&@Contains(T2;“F”);“2”;T1=5&@Contains(T2;“SA”);“3”;T1=5&@Contains(T2;“SU”);“4”;T1=5&@Contains(T2;“M”);“5”;T1=5&@Contains(T2;“TU”);“6”;T1=5&@Contains(T2;“W”);“7”;T1=5;“8”;

T1=6&@Contains(T2;“F”);“1”;T1=6&@Contains(T2;“SA”);“2”;T1=6&@Contains(T2;“SU”);“3”;T1=6&@Contains(T2;“M”);“4”;T1=6&@Contains(T2;“TU”);“5”;T1=6&@Contains(T2;“W”);“6”;T1=6&@Contains(T2;“TH”);“7”;T1=6;“8”;

T1=7&@Contains(T2;“SA”);“1”;T1=7&@Contains(T2;“SU”);“2”;T1=7&@Contains(T2;“M”);“3”;T1=7&@Contains(T2;“TU”);“4”;T1=7&@Contains(T2;“W”);“5”;T1=7&@Contains(T2;“TH”);“6”;T1=7&@Contains(T2;“F”);“7”;T1=7;“8”;

“”)


—added later—


using the variables described elsewhere in this thread the above code would be more efficient like this:

_DayCode := @RightBack(RouteCode;“-”);

_Mon := @Contains(_DayCode;“M”);

_Tues := @Contains(_DayCode;“TU”);

_Wed := @Contains(_DayCode;“W”);

_Thurs := @Contains(_DayCode;“TH”);

_Fri := @Contains(_DayCode;“F”);

_Sat := @Contains(_DayCode;“SA”);

_Sun := @Contains(_DayCode;“SU”);

_Wkday := @Weekday(@Today);

@If(

_Wkday=1&_Sun;“1”;“1”;_Wkday=1&_Mon;“2”;_Wkday=1&_Tues;“3”;_Wkday=1&_Wed;“4”;_Wkday=1&_Thurs;“5”;_Wkday=1&_Fri;“6”;_Wkday=1&_Sat;“7”;_Wkday=1;“8”;

_Wkday=2&_Mon;“1”;_Wkday=2&_Tues;“2”;_Wkday=2&_Wed;“3”;_Wkday=2&_Thurs;“4”;_Wkday=2&_Fri;“5”;_Wkday=2&_Sat;“6”;_Wkday=2&_Sun;“7”;_Wkday=2;“8”;

_Wkday=3&_Tues;“1”;_Wkday=3&_Wed;“2”;_Wkday=3&_Thurs;“3”;_Wkday=3&_Fri;“4”;_Wkday=3&_Sat;“5”;_Wkday=3&_Sun;“6”;_Wkday=3&_Mon;“7”;_Wkday=3;“8”;

_Wkday=4&_Wed;“1”;_Wkday=4&_Thurs;“2”;_Wkday=4&_Fri;“3”;_Wkday=4&_Sat;“4”;_Wkday=4&_Sun;“5”;_Wkday=4&_Mon;“6”;_Wkday=4&_Tues;“7”;_Wkday=4;“8”;

_Wkday=5&_Thurs;“1”;_Wkday=5&_Fri;“2”;_Wkday=5&_Sat;“3”;_Wkday=5&_Sun;“4”;_Wkday=5&_Mon;“5”;_Wkday=5&_Tues;“6”;_Wkday=5&_Wed;“7”;_Wkday=5;“8”;

_Wkday=6&_Fri;“1”;_Wkday=6&_Sat;“2”;_Wkday=6&_Sun;“3”;_Wkday=6&_Mon;“4”;_Wkday=6&_Tues;“5”;_Wkday=6&_Wed;“6”;_Wkday=6&_Thurs;“7”;_Wkday=6;“8”;

_Wkday=7&_Sat;“1”;_Wkday=7&_Sun;“2”;_Wkday=7&_Mon;“3”;_Wkday=7&_Tues;“4”;_Wkday=7&_Wed;“5”;_Wkday=7&_Thurs;“6”;_Wkday=7&_Fri;“7”;_Wkday=7;“8”;

“”)

Subject: RE: Stopping code once a @if is true in Column formula

Both suggestions worked great. Thanks for the suggestions. I know when I’m stuck I can always count on this group.

Subject: Stopping code once a @if is true in Column formula

Hi!

Have a look at @Return().

Subject: RE: Stopping code once a @if is true in Column formula

Thanks for the response. The @Return is normally what should be used, but @Return cannot be used in Column formulas. I’m hopeing that there is another method out there.

Subject: RE: Stopping code once a @if is true in Column formula

Sorry, I lost sight of that. Rewriting the formula (see other responses) shoud do the job.

Subject: Stopping code once a @if is true in Column formula

You could re-write the formula as follows, it should eliminate some unneeded @Ifs…

_DayCode := @RightBack(RouteCode;“-”);

_Mon := @Contains(_DayCode;“M”);

_Tues := @Contains(_DayCode;“TU”);

_Wed := @Contains(_DayCode;“W”);

_Thurs := @Contains(_DayCode;“TH”);

_Fri := @Contains(_DayCode;“F”);

_Sat := @Contains(_DayCode;“SA”);

_Sun := @Contains(_DayCode;“SU”);

_Wkday := @Weekday(@Today);

@If(

_Wkday=1; @If( _Sun; “1”; _Mon;“2”; _Tues;“3”; _Wed;“4”; _Thurs;“5”; _Fri;“6”; _Sat;“7”; “8”);

_Wkday=2; @If( _Mon; “1”; _Tues; “2”; _Wed; “3”; _Thurs; “4”; _Fri; “5”; _Sat; “6”; _Sun; “7”; “8”);

_Wkday=3; @If( _Tues;“1”; _Wed;“2”; _Thurs;“3”; _Fri;“4”; _Sat;“5”; _Sun;“6”; _Mon;“7”; “8”);

_Wkday=4; @If( _Wed;“1”; _Thurs;“2”; _Fri;“3”; _Sat;“4”; _Sun;“5”; _Mon;“6”; _Tues;“7”; “8”);

_Wkday=5; @If( _Thurs;“1”; _Fri;“2”; _Sat;“3”; _Sun;“4”; _Mon;“5”; _Tues;“6”; _Wed;“7”; “8”);

_Wkday=6; @If( _Fri;“1”; _Sat;“2”; _Sun;“3”; _Mon;“4”; _Tues;“5”; _Wed;“6”; _Thurs;“7”; “8”);

_Wkday=7; @If( _Sat;“1”; _Sun;“2”; _Mon;“3”; _Tues;“4”; _Wed;“5”; _Thurs;“6”; _Fri;“7”; “8”);

“”)