![]() Some programmers or developers would regard this as a matter of personal style. Sometimes it's not necessary and then it's up to you. So if it's necessary, absolutely, make the default result explicit. Now in this case, I could have left it blank - I could have stopped after the comma at the end of the line for Saturday, closed the parentheses and gone home. Here I've included a default response of null or nothing (the empty quotes). ![]() Now we can fix that by making the test for Saturday an explicit part of the switch, rather than the default: SWITCH( Here using a default or none-of-the-above response makes sense.īut what if the field containing the reference date is empty? The formula will return "Hmm, it must be Saturday" - but that's wrong. If I'm absolutely sure that the reference date is there, that there actually is a reference date value (and it's a valid date), then the formula above is okay. ![]() In my earlier reply I gave this example of SWITCH(): SWITCH( ![]() Should you use that 0, that is, should you specify a default? Well, you definitely should when it matters. The "0" is just the default or "none of the above" response - which is to adjust the calculated date by 0 days. Now to determine what adjustment to make, you have the SWITCH statement, and you seem to understand that now. The first or "outer" DATEADD statement is the one that makes a (potential) adjustment to the inner statement (in case the initially calculated date is a weekend). The second or "inner" DATEADD statement is the main one: it takes your reference date and subtracts 70 days or 56 days. In both parts of the formula (the November/May part, and the default part for the rest of the year) there are two DATEADD() statements, one inside the other. If nothing matches, the weekday must be 6, so it's Saturday. THEN it works its way down the list of possible matches, with the result for each one in case of a match. So the first part of the statement looks at the date in the date field, calculates its weekday value. The WEEKDAY() function returns 0 for Sunday, 6 for Saturday, etc.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |