1,804 articles and 14,860 comments as of Thursday, May 19th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Tuesday, June 2, 2009

Taming the Elusive “Calculated Column” – Date and Time – Part 4

Now that we’ve gone through 4 test cases that show the calculations being performed, let’s go back to our “Plain English” translation and see how much cleaner it becomes.

Deciphering the Puzzle (v2.0)

Our condition:

If the “End Date” (number) is less than the “Start Date” (number), AND if the “Start Date” (number) minus the “End Date” (number) is greater than 1, do the following:

Count the number of days that separate the “Start Date” from the “End Date” then add 1 to that number.  From that number, subtract the number of days that separate the “Start Date” from the “End Date” plus 1, divided by 7, rounded down to the nearest 1 number, then multiplied by 2.  From this number, subtract 2 from the final result to take in account for weekend days to produce our final result.

If either or both, of the two parts of the condition are not “TRUE”, do the following:

Count the number of days that separate the “Start Date” from the “End Date” then add 1 to that number.  From that number, subtract the number of days that separate the “Start Date” from the “End Date” plus 1, divided by 7, rounded down to the nearest 1, then multiplied by 2 to produce our final result.

Still a little complex, but much easier to comprehend.

Summary

Sometimes, the obvious answer to a solution may be obscured by itself (as confusing as that very statement might sound, try going back to my original wording of the formula used in this series and attempt to read it aloud in a single breath – I can do it in 3 – barely, and I wasn’t sure what I had just read by doing it so quickly).

“DATEDIF” seems like the obvious choice for our problem, but since it’s rather literal in what it does, it counts each and every day in between two dates, including weekends, which is not exactly what we want.

In Excel, this is almost trivial because of how easy it is to come up with the solution, we just use “NETWORKDAYS”, plug in the start and end dates and voilà, we have an accurate count that magically excludes weekend days (again, another of the numerous functions they did not include in SharePoint for some reason). 

The unfortunate side of this is that even if you run the “Evaluate Formula” command within Excel on the “NETWORKDAYS” function, you can’t see each and every step being performed in the calculation to see just how it skips the weekend days in the end result.  This function obscures itself by not showing you “how” it does what it does (far too many Excel functions have this same limitation unfortunately).   But, given the functions available (within Excel, and SharePoint), we can attempt to “duplicate” what it’s doing by using several functions together that will “logically” return the exact same result, just through a much longer process.

Hopefully all of this wasn’t too confusing – it’s a hard formula to decipher, but as with all formulas, the best approach is to break it into chunks, determine what each chunk does independently, then merge them all back together and run through the entire thing with a series of test data.
Till next time…

- Dessie

Dessie LunsfordDessie Lunsford
Points-of-Sharing

View all entries in this series: Dessie Lunsford-Logic Formulas»
Entries in this series:
  1. Taming the Elusive "Calculated Column"
  2. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Task List
  3. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part II)
  4. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part III)
  5. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Task List (Part IV)
  6. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Text and Data
  7. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part I)
  8. EndUserSharePoint.com: Taming the Elusive "Calculated Column" - Customizing a Contacts List (Part II-I)
  9. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-II)
  10. EndUserSharePoint.com: Taming the Elusive “Calculated Column” - Customizing a Contacts List (Part II-III)
  11. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part III)
  12. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part IV)
  13. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part V)
  14. EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Text and Data (Part VI)
  15. Taming the Elusive “Calculated Column” – Lookup and Reference
  16. Taming the Elusive “Calculated Column” - Logic
  17. Taming the Elusive “Calculated Column” - Logic - Part 1
  18. Taming the Elusive “Calculated Column” - Logic - Part 2
  19. Taming the Elusive “Calculated Column” - Logic - Part 3
  20. Taming the Elusive “Calculated Column” - Logic - Part 4
  21. Taming the Elusive “Calculated Column” - Logic - Part 5
  22. Taming the Elusive “Calculated Column” - Logic - Part 7
  23. Taming the Elusive “Calculated Column” - Logic - Part 6
  24. Taming the Elusive “Calculated Column” - Logic - Part 8
  25. Taming the Elusive “Calculated Column” - Logic - Part 9
  26. Taming the Elusive “Calculated Column” - Logic - Part 10
  27. Taming the Elusive “Calculated Column” - Date and Time - Part 1
  28. Taming the Elusive “Calculated Column” - Date and Time - Part 2
  29. Taming the Elusive “Calculated Column” - Date and Time - Part 3
  30. Taming the Elusive “Calculated Column” - Date and Time - Part 4
  31. Taming the Elusive “Calculated Column” - Referencing Multiple Lines of Text Column
  32. Taming the Elusive “Calculated Column” – Date and Time – Part 5
  33. Taming the Elusive “Calculated Column” – Date and Time – Part 6
  34. Taming the Elusive “Calculated Column” – Date and Time – Part 7
  35. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 1
  36. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 2
  37. Taming the Elusive "Calculated Column" - Referencing a Multiple Lines of Text Column With Append Text: Part 3
 

Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!