1,451 articles and 9,898 comments as of Monday, March 22nd, 2010

Thursday, July 24, 2008

EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Customizing a Task List (Part IV)

Task ListDessie Lunsford
Points-of-Sharing

If you haven’t read through the previous three articles in this series (Part I, Part II, Part III), I would encourage you to read them first as we’ll be continuing on with the use of an Excel spreadsheet developed in each of them.

 

 

Review and Next Steps

In the last article, we created a calculated column which gave us the ability to see if a task had been completed early. This type of information could be beneficial to managers performing an audit of a particular users (or groups) performance in completing items in a timely manner.

This time, we’ll be completing our customization of the “Tasks” list by adding in our final column called “Overdue?”.

The Formula

The “Overdue?” column is used to see “At-a-glance” which tasks are currently overdue and display a simple “Yes” or “No” depending on its status (which could assist in the day-to-day management and processing of Tasks).

Compared to previous examples, this column is rather straight-forward in its formula and what it’s looking for, but at the same time it can be somewhat confusing unless you understand the structure and logic of the formula and how it works to produce a specific result.

(See the previous articles in this series to create and setup your Excel spreadsheet.)

Formula in Excel:
=IF(AND(B7<TODAY(),B4 <> “Completed”),”Yes”,”No”)

Once again we see our old friend, the “IF” statement, as well as the “AND” function we discussed last time.

Dissecting this formula, we begin with the “IF” and its three parts:

  1. The logical condition to check (is the “Due Date” less than today’s date? AND is the value of the “Status” column not equal to “Completed”?)
  2. Value if “True”(display the text “Yes”)
  3. Value if “False” (display the text “No”)

In the formula’s conditions, our first check is looking to see if the “Due Date” is less than “Today’s” date. If it is, the result of the first check is “True”. This is “technically” ok by itself, but it doesn’t deal with tasks that haven’t been completed yet, so we need to combine this with a second check to see what the “Status” is of the task.

For the second check, instead of looking to see if a specific value exists, we’re looking to see if it doesn’t. In this case, if the “Status” field does not equal “Completed” then the result is “True” (anything else will yield a result of “False”). Again, by itself this doesn’t really help us because not every task that hasn’t been completed is overdue (it wont be overdue until we have moved past the actual due date).

Combining multiple checks together (up to 30 of them) is a form of what’s known as “Boolean Logic“. To accomplish our end result of either “True” or “False” for the combination of these checks, we’re going to use an “AND” statement to merge our two checks into one statement that must be “True” (as a whole) in order to produce a result of “Yes” being displayed (note – the “AND” by itself will only produce a “TRUE / FALSE” result, so by adding it to an “IF”, we can then control the displayed output of “TRUE” being displayed as “Yes” and “FALSE” being displayed as “No”).

If we use another type of “Logic Diagram” tool called a “Truth Table“, we can check each combination of values to see just what results are possible.

Input1 (1st check) Input2 (2nd check) Result of each End Result
Due Date is less than today Status not equal to “Completed”

TT

TRUE

Due Date is not less than today Status not equal to “Completed”

FT

FALSE

Due Date is less than today Status is equal to “Completed”

TF

FALSE

Due Date is not less than today Status is equal to “Completed”

FF

FALSE

 

The “Truth Table” although depicted rather simply here, can be used in conjunction with advanced calculations as well. In future posts, I’ll dive deeper into the use of this tool to aid in checking your formula logic.

In our formula (and following the examples in the Truth Table):

  1. If the “Due Date” is less than “Today” (meaning we’re currently past the “Due Date”) and the “Status” field does not equal “Completed”, the entire comparison is “True” which results in a “Yes” being displayed (True: True).
  2. If the “Due Date” is not less than “Today” (meaning we still have time left) and the “Status” field does not equal “Completed”, the entire comparison is “False” which results in a “No” being displayed (False: True).
  3. If the “Due Date” is less than “Today” (again, meaning we’re currently past the “Due Date”) and the “Status” field is equal to “Completed”, the entire comparison is “False” which results in a “No” being displayed (True: False).
  4. If the “Due Date” is not less than “Today” (again, meaning we still have time left) and the “Status” field is equal to “Completed”, the entire comparison is “False” which results in a “No” being displayed (False: False).

In the above four possibilities, the only result that will display a “Yes” is if we’re past the “Due Date” and the “Status” is anything but “Completed (each of the other three will either mean the task has been completed or we still have time left).

Testing this in Excel is as follows.

Enter a start date in the past and a due date in the future (notice the “Overdue?” column displays “No” indicating the task is currently not overdue):

Change the due date to be yesterday (notice the “Overdue?” column displays “Yes” indicating that we’re currently past the due date and that the task is overdue):

Modify the task again and set the status as “Completed” (notice the “Overdue?” column now displays “No” since the task is completed).

One extra thing to point out in the logic of this column is that it really only applies to tasks that are open. Once a task is completed we’re not concerned with it being overdue anymore, so after its completion it will always display a “No” (we’re using the “Completed Early?” column to inform us of tasks that were completed ahead of schedule, so adding in logic for that information on this column would be redundant).

To get this into SharePoint, we follow the same approach as before:

In SharePoint, go into the “Tasks” list and its settings Page.

Since we’re once again using a “Today” reference in our formula, we’ll need to create our temporary “Today” column that will allow us to use the reference without displaying any errors.

Create a new column called “Today” leaving the rest of its settings as default.

Next, create another new column called “Overdue?”, make it a “Calculated” type and paste in the formula from Excel. Before saving, replace “B7″ with “[Due Date]” and “B4″ with “Status” (making sure to include the brackets [] around “Due Date” so the system will recognize it as a column).

Formula in Excel:
=IF(AND(B7<TODAY(),B4 <> “Completed”),”Yes”,”No”)

Formula in SharePoint:
=IF(AND([Due Date]<Today,[Status] <> “Completed”),”Yes”,”No”)

After you have the new calculated column, we need to go back and delete our temporary “Today” column (as discussed previously, this column was simply a placeholder that fools the system into allowing us to use the name for our formula, so deleting it will now match it up with the real “Today” data in the system, but without throwing an error).

To test our new column, create a new item on the list with a “Start Date” of the (default) current date and a “Due Date” of tomorrow.

Once saved, we can see that our new column displays a value of “No” indicating that the task is not completed and that we still have time to complete it before it comes due.

Our first check is to see if the “Due Date” is less than the current date. In this case, since the “Due Date” is tomorrow (greater than today, not less than), the result is “False”. The second check is looking to see if the value of the “Status” column is “less than or greater than” (equivalent to the statement “Not equal to”) the text “Completed”, which is “True” since the task is in fact not completed. Since both checks are not “True” (first is “False”, second is “True”), the entire check is “False” which results in a display of the text “No”.

Looking back at our “Truth Table“, we see that any combination of the two checks that results in anything other than the two of them being “True” will result in the entire check being “False”, which in this case, is our final result and displays the text “No”.

To test what other values could be displayed, we simply modify the details of the task to see what the results are.

Set the “Start Date” back a couple of days and the “Due Date” to today’s date (notice how the value remains “No”?).

Since the “Due Date” is not less than today’s date (it’s equal), the first check is “False”. The second check however, is “True” since the value of the “Status” field does not equal “Completed”, so since both checks do not result in “True”, the entire check is “False” resulting in “No” being displayed.

Modify the item again, but this time set the “Due Date” to yesterday (notice how the value now display’s a “Yes”?).

In this example, the first check is “True” since the “Due Date” is less than the current (”Today”) date. The second check is also “True” since the value of the “Status” field does not equal “Completed”. As a result of both checks being “True”, the entire condition is “True” which gives us a displayed result of “Yes” indicating that the task has not been completed and is currently overdue.

Modify the item once again and mark the task as completed (notice how the value now display’s “No”?).

For this one, without even looking at the first check we know immediately that this will display a value of “No”. Why? Because in the second check we’re looking at the value of the “Status” field, and testing to see if it “Does Not” equal the text “Completed”. Literally, if it equals anything but the text “Completed” it will be “True”. Since we’ve set the task as completed, it will now automatically become “False”. Because of this, no matter what possible value could be in the first check, the entire (combined) check will always be “False” for the simple reason that the second check is “False”. So, once the task is completed it is no longer overdue (logically, this should make sense).

Summary

Putting all of this together, let’s take a quick look at what we’ve accomplished throughout this series and how to make it an effective solution for making the “Tasks” list more useful.

Our five calculated columns we’ve created are:

  1. Date Completed” – Uses the “Today” reference to mark when a task was completed.
  2. How many days left to complete?” – Visual indicator of time left on a task.
  3. Days Overdue” – Advanced version of the “How many days left to complete?” column with better information.
  4. Completed Early?” – Visually indication of tasks completed ahead of schedule.
  5. Overdue?” – At-a-glance view of tasks that are overdue.

Through each of these articles, we’ve worked with multiple functions (some separate, some in concert with each other):

  • IF – Conditional statement containing three parts (logical condition to check, value if true, and value if false) that allows us to display a particular result based on a check of a given condition.
  • AND – Boolean operator that allows us to check multiple conditions at the same time where each individual check must equal true in order for the whole (combined) condition to result in true.
  • TEXT – Conversion function that takes a value and converts it to text in a specified “number” format.
  • INT – Math function that simply rounds a given number down to it’s nearest integer.
  • ISERROR – “Error trapping” function that gives us the ability to decide what will be displayed if an error is discovered somewhere in our calculation.

And, we’ve also worked quite a bit with the “Today” reference and how to use it in a Calculated Column (despite Microsoft’s own documentation stating that it can’t be done) by using a temporary column to bypass the infamous SharePoint error messages.

In the “Out of the box” implementation of the Tasks list, the functionality is limited, as it only gives us information as to when the task is due, a percentage of its current completion and status.

By adding in our custom columns, we can now see if a task is overdue, how many days it’s overdue or have left, the date it was completed, and whether or not it was completed ahead of schedule. With these new columns, the possibility for custom views begin to surface allowing us more advanced ways of filtering tasks for the users they are assigned to, those that review the tasks, and those that are responsible for reporting and auditing task history after task completion.

(Simple Custom Views)

Example of custom view for assignees:

Example of custom view for mangers:

Example of custom view for auditors:

In future articles, we’ll be covering more functions and more advanced formulas that will give us even more power in how we view data (perhaps even a few more additions to the “Tasks” list).

Till next time…

– Dessie

Suggestions for future posts on calculated columns are always welcome, and if fact are encouraged.

Some of the best scenarios to illustrate are the “real-world” problems that we each face day to day, so if you have an example, an idea you want to explore, or a “Can this be done with a Calculated Column?” question that I can use as the topic of a future post, please submit it as a comment below and I’ll see what I can do to work up a post covering it.

Dessie LunsfordDessie Lunsford
Points-of-Sharing
“I enjoy figuring out how to get my users to understand what they can do with SharePoint, and “how to do it” – this is probably the biggest hurdle my users have to face.”

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
 

Please Join the Discussion

26 Responses to “EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Customizing a Task List (Part IV)”
  1. Charlie Epes says:

    Dessie:
    This is a tremendously well put-together instructional article. You are a true teacher. Thanks!
    Charlie

  2. Charlie – Please don’t say those things out loud. We’re trying to keep Dessie around for a while before he gets sucked up into the big SharePoint Machine in the sky.

    Mark

  3. Greg says:

    Just a quick note to say “thank you” for the amazingly thorough and well-explained tutorial. The best series of articles on calculated columns I’ve seen so far. Thanks again and I’m looking forward to seeing more posts from you…

    Greg

  4. Adrian says:

    I am quite newby in the SharePoint universe.
    Thanks a lot, Dessie!!!!

    I found your columns very instructive!

    Looking forward to your next posts!

  5. Lp12 says:

    Thanks a lot for these cool tips.
    I’ve created calculated fields but I’ve got complaints from the users, that they don’t what to see those fields when they view the items. Is it possible to hide them in any way?
    Thanks again

  6. Dessie says:

    Thanks for all the kind words everyone…I do appreciate it!!

    Lp12,
    When you view the details of an item, it will always display all of the columns that are defined for it…that is, the list of columns in the lists settings. I’m not sure if there is an easy way of “trimming” that information down since it’s designed to display all of the information at once, when viewing the “details” of an item.

    You may be able to modify the “DispForm.aspx” page to see if there’s a way to limit what’s displayed, but I haven’t tried…perhaps someone else may have an idea here?

    - Dessie

  7. Dennis says:

    Hi Dessie!

    Thanks for such a remarkable set of articles. This articles just fabulous masterpieces. It really makes my life easier now. Keep on writing!

    By the way – are you planning any other articles on calculated columns? Is there any way of building calculated column with fixed length by adding zeros to the left side of column value? For example, could it look like the result of PadLeft() function – if user enters “123″ the column should convert it into “000123″ and so on.

    Thanks,
    Dennis

  8. I have been trying for quite a while to configure a calculated column based on a “People or Group” column. It appears as if this is not possible.
    What I was hoping to do was have a user search for a person in Directory Services (via the form input) and when a person is selected break off the first and last names into separate columns for use later.

    Is this possible?

    thanks in advance

    tom baumgartner

  9. Dessie says:

    Dennis,
    Thanks for the comments…I’m glad that what I’m writing about is actually helping :) (and yes, I have quite a few more articles in store)

    To deal with the “padding” issue, there’s probably several ways to approch this, but here’s a quick way to get what you want:

    Let’s assume we have a column called “Number” (in number format) that houses the value a user would enter.
    Create a new column called “Padded Number” giving it the following calculation:

    =IF(LEN(Number)<10,REPT(0,(10-LEN(Number)))&Number,TEXT(Number,”0″))

    This will check the length of the value entered to make sure it’s less than 10 characters (change this to the value you want) and if it is, adds the character “0″ to the left of the number as many times as neccessary to make the entire character count equal 10 (calculates the difference between 10 and the length of what was entered). If it’s not less than 10, it simply displays the entered number.

    My next set of articles will be with the “Text and Data” set of functions for calculated columns so I’ll be expanding on this very idea that you asked.

    - Dessie

  10. Dessie says:

    Tom,
    Unfortunately, you cant do calculations against a “People and Groups” type column (one of the limitations on calculated columns).

    One possibility is to create a SPD workflow that builds a dynamic string on the value of the lookup (people and group column) and assigns it to another column which you can then perform a calculation on to separate the parts of the name out.
    In my testing however, the result of the workflow will most likely render the name in the format of “Domain\login” instead of the “Display name”, so this may not work for you either.

    I havent tried it, but you could also look at the “Custom Workflow Activities” project on codeplex (http://www.codeplex.com/SPDActivities) that adds in custom actions (one of which is a lookup on user information for a given login – might get the “Display Name”) that might let you get the data you want in a custom workflow.

    - Dessie

  11. Andrew Caw says:

    Hi Dessie

    Thanks for this article – I was just about to setup my new sharepoint task list when I found this – perfect timing!

    I’ve setup these calculated columns but I have one problem:
    The Columns don’t auCtomatically update. I have to add the TODAY column & then remove it again to get the calculated columns to update.

    Is anyone else having this issue or is it just me?

    Thanks
    Andrew

  12. Dessie says:

    Andrew,
    Calculated columns are by nature “static”, meaning that the calculations take place when something changes on the item (new item created, existing item modified, etc). Because of this, the “Today” reference will only be calculated once until something changes on the item again to force it to recalculate.

    Unfortunately with this being a limitation of using the reference in a calculation, in order to make effective, you have to have a process in place that performs updates which will fire off the calculation additional times when needed.

    I have a post on my blog that discusses this and offers a few (possible) solutions, or workarounds that might help (two of them are “coded” solutions – http://www.sharepointblogs.com/dez/archive/2008/07/31/dynamically-updating-a-sharepoint-calculated-column-containing-a-quot-today-quot-reference.aspx).

    The point of these articles are an attempt to illustrate how to use different functions in calculated columns (along with the flaws that come with them), and provide better explanations as to how they really work. One piece that I neglected to cover (which you have now pointed out) is that the “Today” reference might be best used for displaying data that doesn’t neccessarily need to be updated daily, and that if it does, you’ll need to make sure and setup something that will update the items (possibly on a scheduled basis through a, SPD workflow) to force a recalculation.

    Thanks, for pointing this out…I’ll make sure and cover this better in future posts.

    - Dessie

  13. Steve says:

    Help!!

    Is there a way to do create a calculated field based on the status of a workflow column is a list?

    This post is something that I found that is similar to my request:
    http://forums.msdn.microsoft.com/en-US/sharepointcustomization/thread/12496094-e76e-4eb0-bc11-e187e18d19da/

    Thanks so much!

  14. Don Zielke says:

    I can’t believe that there’s not a way to display a task list with a filter that say “Show me all records that have a Modified date within the past 7 days”. What am I missing? I’m going through your calculated column stuff now (sorry if it’s already been answered), but is there a way to do a filter on the Task list “Modified” date field that shows all records that have been modified within the past 7 days? Can I filter directly on the Modified field or do I need a calculated column field?

  15. Dessie says:

    Steve,
    You’ll probably have to create a custom workflow for this since you cant directly reference a workflow status field in a calculated column.

    One approach you could try is creating a separate column that is simply used as a placeholder for the value of the workflow (status) field (just set it a the default text-type field).

    In your workflow, have it update the “placeholder” column in the list item with the status of the workflow (might need to set up an “IF-ELSE” in the workflow to check what the status is). Most likely, the list item will not display the status immediately because of the short delay that occurs before the workflow is finished, but refreshing the page a few seconds after saving should update the field to display the status (or just revisit the page later).

    Once you have the value in the placeholder column, you can then reference it in a calculated column and do whatever other processing you want.

    Hopefully this will at least get you going in the right direction,

    - Dessie

  16. Dessie says:

    Don,
    You should just be able to set your filter as:

    “Modified”
    is greater than or equal to
    [Today]-7

    Have you tried this already?

    - Dessie

  17. Don Zielke says:

    Dessie – Well, I feel a little foolish but I did figure something out. What you gave me above didn’t work. I got an error message that said “filter value is not a valid date”. BUT… your suggestion gave me an idea.

    I created a calculated field called Calc-Date, and set it to [Modified]+7. I then created a filter that looked at Calc-Date [Today]. Works like a champ.

  18. Don Zielke says:

    Whoops! part of my text didn’t post… my filter was set to:

    Calc-Date “is-greater-than-or-equal-to” [Today]

  19. Don,

    I’m happy to hear you got it working :)

    - Dessie

  20. Dishaniti says:

    A simple question regarding Due Date

    Is this possible to validate Due Date at the time of New Item and Edit Item?

  21. Dishaniti,
    Adding in some JavaScript may be your only option on this (script that performs the validation of entered data).

    I’d suggest posting the question on the “STP” forum.

    - Dessie

  22. Angela says:

    Dessie -
    I have a simple calculation 3/1/09 + 180 days as my DUE DATE. However, I cannot get gantt view to recognize the calculated date. What am I doing wrong?

  23. Mike says:

    Hi,

    i am using room and equipment reservation template, i want the start date to be equal or greater than today.

    how cna i do that ?

    Thanks for any help.

Trackbacks

Check out what others are saying about this post...
  1. [...] EndUserSharePoint.com: Taming the Elusive “Calculated Column” – Customizing a Task List (Part IV… [...]

  2. [...] a number of times (useful in adding a series of repeated characters to an existing string – see this comment for an example of [...]

  3. [...] One approach you can take with this is to build out your own type of ID numbering system that follows a specific pattern, or total character count (mentioned in a previous article comment). [...]




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!