hello
on this condition I have a strange thing: it treats the condition for A, B and WEA
but for C and WEB it does not take it
I don't know why
If(DayOfWeek(PrepareLog.Log.DetectedOn) > 0 and DayOfWeek(PrepareLog.Log.DetectedOn) < 6 and (Hour(PrepareLog.Log.DetectedOn) >= 6 and Hour(PrepareLog.Log.DetectedOn) < 14), "A", If(DayOfWeek(PrepareLog.Log.DetectedOn) > 0 and DayOfWeek(PrepareLog.Log.DetectedOn) < 6 and (Hour(PrepareLog.Log.DetectedOn) >= 14 and Hour(PrepareLog.Log.DetectedOn) < 22), "B", If(DayOfWeek(PrepareLog.Log.DetectedOn) > 0 and DayOfWeek(PrepareLog.Log.DetectedOn) < 6 and (Hour(PrepareLog.Log.DetectedOn) >=22 and Hour(PrepareLog.Log.DetectedOn) < 6), "C", If(DayOfWeek(PrepareLog.Log.DetectedOn) = 0 or DayOfWeek(PrepareLog.Log.DetectedOn) = 6 and (Hour(PrepareLog.Log.DetectedOn) >= 6 and Hour(PrepareLog.Log.DetectedOn) < 18), "WEA", If(DayOfWeek(PrepareLog.Log.DetectedOn) = 0 or DayOfWeek(PrepareLog.Log.DetectedOn) = 6 and (Hour(PrepareLog.Log.DetectedOn) >= 18 and Hour(PrepareLog.Log.DetectedOn) < 6), "WEB", "Nothing")))))
Thank you
Hi Ibtissam,
Let's first simplify your condition by replacing the DayOfWeek and Hour by a simple variable:
If(Day > 0 and Day < 6 and (Hour >= 6 and Hour < 14), "A", If(Day > 0 and Day < 6 and (Hour >= 14 and Hour < 22), "B", If(Day > 0 and Day < 6 and (Hour >= 22 and Hour < 6), "C", If(Day = 0 or Day = 6 and (Hour >= 6 and Hour < 18), "WEA", If(Day = 0 or Day = 6 and (Hour >= 18 and Hour < 6), "WEB", "Nothing")))))
The first thing I notice is that you repeat the "Day > 0 and Day < 6" three times, and the "Day = 0 or Day = 6" two times. My recommendation would be to simplify that, which makes it faster and much more readible:
if (Day > 0 and Day < 6, if (Hour >= 6 and Hour < 14, "A", if (Hour >= 14 and Hour < 22, "B", if (Hour >= 22 and Hour < 6, "C", "???"))), // else if (Hour >= 6 and Hour < 18, "WEA", if (Hour >= 18 and Hour < 6), "WEB", "???") )
As Dorine already told you, something can't be both be larger than 22 and smaller than 6 (or larger than 18). That's just a logical error in your code. I truely hope you can see that there's an error there. That said, the solution is easy, just do not specify that condition at all but use it as an else:
if (Day > 0 and Day < 6, if (Hour >= 6 and Hour < 14, "A", if (Hour >= 14 and Hour < 22, "B", "C"))), // else if (Hour >= 6 and Hour < 18, "WEA", "WEB") )
Note though that I'd consider this all very, very basic programming skills, so if you feel this is above your head, perhaps you should consider some more training material...
I'd say most of it is logical thinking. And practice would help, definitely, as well as checking existing code. And sometimes taking a step back and try to think in functional terms rather than technical ones.
Hi Ibtissam, an integer can't be at the same time larger than 22 and smaller than 6
you probably want a few or instead of and in there