Calculated Fields don't leave home without them

Being new to Bamboo and SharePoint, most of my time is spent on self learning and working on custom solutions.  Working on custom solutions means interacting with customers, which is the best part of my job as this is where I get to see how Bamboo Web Parts are being used as part of a process or an overall solution and not just as an end point or tool in themselves. This is the most creative aspect of my job as our first task usually is to understand the real need behind the request which allows us to sometimes suggest a change to the approach and resolve the issue by using out of the box SharePoint or by stringing together some Bamboo web parts. Here are a few examples of how we used calculated fields as the solution for some of our customers business needs.

1.  The custom request that wasn't - it came from a customer using the Bamboo Alert Plus Web Part to send alerts to task assignees one day before the task is due. The web part worked fine, except for the people who had tasks due on Mondays. These people couldn't benefit from the alert because they were rarely in the office on Sunday to see the email message. For tasks due on Monday, the customer wanted to send the alert the preceding Friday. They called and asked for a custom version of our Alert Plus web part

A calculated field came to the rescue (no customization needed), we just needed to add the field to the list and configure the alert differently. Here's how we changed the Tasks List first:

  1. Create a calculated column (data type = single line of text) in the Tasks list to store the day (i.e. Monday) the task is due. The calculation for this column is: “=TEXT(WEEKDAY([Due Date]),"dddd")”. Call this column “Day”.
  2. Create another calculated column (data type= Date and Time) called “Alert Date” in the Tasks list to store the day the alert should be sent. The calculation for this column is: “=IF(Day="Monday",[Due Date]-3,[Due Date]-1)
  3. Create a view in the Tasks list called Alert that includes all incomplete tasks where “Alert Date” = [Today].
  4. Create a Bamboo alert for the Task List for items in this view  which will trigger the alert  on the days when an item is present in this view

2.  Jeff, a member of the Bamboo Solutions team recently showed a customer how to solve his dilemma by using a calculated field. This customer was looking for a way to provide a unique incremental identification code for each item in a list. The code needed to have a set prefix followed by an incremental number.  For example with our projects, we have PXXX for our custom project numbers where the XXX is an incremental number, like P001, P003, etc.  You can create an incremental identification code by using calculated fields and the ID column.  Our customer wanted to display PXXXX where XXXX is a 4 digit incremental.  To achieve this you create two columns.  The first one defines how many zeroes you need to prefix the ID with since you always want XXXX to be four digits.  The second one stores the value for the incremental identification code itself. 

In this case the first column was called “ID Set”  and the formula is as follows –

=IF(ID<10,"000",IF(AND(ID<100,ID>=10),"00",IF(AND(ID<1000,ID>=100),"0","")))

As a result if ID is only 1 digit, the result of the column is 000

If ID is 2 digits, the result of the column is 00 - and so on

And if the ID is 3 digits, the results is 0

Else nothing is return.

The next custom column is called “Incremental Form ID” and the formula is as follows –

="P"&[ID Set]&ID

3. Another custom request that wasn't came from a customer wanting to display two lines of information for each event on the Bamboo Calendar Plus Web Part. Since the Web Part allows you to only have one field set as your display field, a calculated field came to the rescue again. In this example I created a calculated field (Display for Calendar) that joined two columns in the Calendar list so I could display the Title and Location for each event in the same field:

 

The result in Calendar Plus now shows the Meeting Title and the Location:

 

I found the logic for calculating "day" on a  Microsoft Office Online page which has a rather extensive list of common formulas that can be used in a list or a library.  So bottom line, sometimes the answer lies in the list itself where a few calculated fields may get you the data you need to group or sort by, set your alert or display on, or filter on and so forth. However, sometimes the data of a calculated field can also limit what you can do with it specially when linking to it or using it as a lookup from another web part so an end to end test of the scenario where you will be applying the data is always the best approach.


Posted Apr 24 2008, 05:13 PM by DaisyAnand

Comments

Todd wrote re: Calculated Fields don't leave home without them
on Tue, Apr 29 2008 9:28 AM

Hi Daisy,

Jeff's solution in number 2 is very clever, I tried it and it worked well initially.  Then when I added new elements to the list, the calculation seemed to not be properly inherited for the new elements in the list.  If I went back into List Settings and opened up the calculated field and then back to the view, the calculation worked again.  Did you run into this when you were playing with calculated fields, that the calculation seems to stop working when you add new items to the list?

DaisyAnand wrote re: Calculated Fields don't leave home without them
on Tue, Apr 29 2008 3:19 PM

Hi Todd,

Thank you for bringing this to our attention, you are correct, the numbers are not being incremented as per our logic.  This is occurring because the ID is not populated until the record has been created in the database.  So all new records have an ID of '0' and thereby returns a result for our calculations based on the zero.  Once the record has been inserted in the database, the database will return the new ID for the record, but too late for our calculated fields to re-calculate. The new ID has to be generated by the database to ensure it is unique (otherwise two users creating a new record at the same time would generate the same ID).  

So since the real data for the ID field is only available after the save, one way to solve for this is to create a workflow (in SharePoint Designer) to auto run when a new item is created , so it kicks-off  after the save and allows us to use the real ID.

First create a new field called FormId, then in SharePoint Designer create a workflow to run when a new item is created, leave the Condition field blank and under Action, select Update Item,  FormId = (current item) ID.   This workflow will now copy the ID field to the FormID field.

Next, change both your calculated fields to run against the FormId field instead of the ID field:

ID Set =IF(FormID<10,"000",IF(AND(FormID<100,FormID>=10),"00",IF(AND(FormID<1000,FormID>=100),"0","")))

Incremental Form ID ="P"&ID Set&FormID

This will result in the assigning an incremental number to a new item when it is created.

Please let me know if this works for you.

Daisy

Michael Marques wrote re: Calculated Fields don't leave home without them
on Tue, Jun 17 2008 1:22 PM

how can this be applied to wss 2.0 since workflow is not an option?

bee wrote re: Calculated Fields don't leave home without them
on Mon, Jul 14 2008 11:52 PM

can we display the calculated field with Date & Location from event?

=[Start Time]&"-"&Location

DaisyAnand wrote re: Calculated Fields don't leave home without them
on Fri, Jul 18 2008 3:37 PM

Hi Bee,

You should be able to display the Time and Location in a calculated field by using the following syntax:

=TEXT([Start Time],"h:mm")&" "&Title

Daisy

Steve wrote re: Calculated Fields don't leave home without them
on Tue, Sep 16 2008 9:41 AM

If i use the =TEXT([Start Time],"h:mm") formula, I get military time.  Is there any way to get 12-hour time?

Duke Bradford wrote re: Calculated Fields don't leave home without them
on Fri, Sep 19 2008 11:39 AM

I am trying to develop a calculated site column for a date. What I'd like to do is this...

Inpection date: July 15, 2008

Inspection Frequency: Annual

Next Due: July 15, 2009

I can't get the "If" code in my calculated column to work...

=IF([Inspection Frequency]="Annual", [Last Inspection] + 365)

I'm new to this so can anyone help? Thanks!

Henry wrote re: Calculated Fields don't leave home without them
on Tue, Oct 7 2008 5:21 PM

Thanks for the workflow tip on setting the FormId.

Instead of all that If stuff for padded zeroes, I just used ="P"&TEXT([FormId], "0000")

Kerstin wrote re: Calculated Fields don't leave home without them
on Wed, Oct 29 2008 7:16 PM

Hi Daisy,

I am attmpting to add the Incremental ID code and was successful in creating all of the items called for in #2.  However, I am a new developer in SharePoint and you mention in your reply to Todd above that we need to create a new field called "Form ID"....Where exactly should this field be created?  

Thank you in advance for your assistance.

Pelica wrote re: Calculated Fields don't leave home without them
on Thu, Nov 6 2008 3:12 PM

Daisy,

We, also, have implemented the Incremental ID and did the workflow and it works great.  Now that we are done with testing, I need to be able to reset the incrementals to "zero" or "1" for all of our libraries.  How would I do this?

Thanks!

Adan wrote re: Calculated Fields don't leave home without them
on Mon, Nov 17 2008 8:53 PM

Hi Daisy,

First. Thank you for the advice on the workflow tip on setting the FormId.

I have used FormId so that I create a lab case that includes labname, year,month, and only 3 digits of the FormId. For example. GLS0811222.

My question is when I create, or should I say add a step to my workflow that sends an email to an individual that includes the case number field, the workflow messes up the ID portion of it. instead of giving me something like above, the email is sent with case number GLS0811000. The ID seems to switch to zero.

Would you have any idea on what could it be.

Thanks.

About DaisyAnand

My name is Daisy Anand and I work in the Solutions team at Bamboo Solutions. I am a newbie at Bamboo and relatively new to Sharepoint. I work with customers who are interested in custom solutions for when a Bamboo Web Part needs a bit of tweaking in order to fit into their implementation. I enjoy the initial discovery phase as sometimes when we uncover the need behind the ask, we end up solving the original issue out of the box or use a new approach and may resolve the need by using a combination of Web Parts with minor tweaks.
Bamboo Solutions Corporation, 2002-2009