Dailycode.info

Short solution for short problems

When we use advanced functions, sometimes we need to reference one calculated field to an other. In Sharepoint this is possible.
And when we accidently make circular references we get this wonderful error:

The formula contains a circular reference (the calculated column refers to itself).  You must remove or change the circular reference.

Here is an example of a formula based on an other calculated field:

=IF(ISNUMBER(FIND("\",[calcfield])),RIGHT([calcfield],LEN([calcfield])-FIND("\",[calcfield])),"")


This fomula checks if the field contains a "\", and if it does, it takes the substring on the right of the "\",
else it displays and empty string: "".

You can find everything on functions that you can use in calculated fields on: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx

Recently I had a nice challange in Sharepiont 2007.
I had to group a view by a field, but not just group it on the text but on part of the value.
Eg. The field contained a value like this: A chapter\a subchapter.
The view had to be grouped by chapter and secondly by subchapter.This is the simple solution to the problem:

I created 2 new calculated fields in the sharepoint list.
The first field called chapter, the second subchapter.
The chapter field had to contain the part of the title field before the "\". And if there was no "\" in the text,
then it had to be the complete string. This is the code I used to create this field:

=IF(ISNUMBER(FIND("\",Title)),LEFT(Title,FIND("\",Title)-1),Title)


First we check if the "\" is present in the string, if not we just use title as it is. If "\" is present, then we take the left of the "\".

Here are some examples:

A testing code\b subtest 2     --> becomes: A testing code

A testing code                      --> becomes: A testing code

The second field had to contain the part of the string after the "\" and in case there was no "\" it had to be empty. Here the code I used:

=IF(ISNUMBER(FIND("\",Title)),RIGHT(Title,LEN(Title)-FIND("\",Title)),"")


First we check if the "\" is present in the string, if not we return "". If "\" is present, then we take the right of the "\".

Here are some examples:

A testing code\b subtest 2     --> becomes: b subtest 2

A testing code                      --> becomes:

Then I grouped the view on these 2 fields.

Since I'm a programmer myself, I know that examples are the best way to learn a code. So here's one more.

This time I had to get some values out of a text field called Soort with this format: text1\text2\text3 .
I had to show text2 and text3 in different columns. The first calculated field called Project contains the string text2.
The code to get text2 out of the string text1\text2\text3 is the following:

=LEFT(RIGHT(Soort,LEN(Soort)-FIND("\",Soort)),FIND("\",RIGHT(Soort,LEN(Soort)-FIND("\",Soort)))-1)


So this code return: text2. The next calculated field called Subproject had to contain the string that is in place of text3.
Since Sharepoint code does not have the possibility to split or use loops we had to come up with the following code:

=RIGHT(RIGHT(Soort,LEN(Soort) - FIND("\",Soort)),LEN(RIGHT(Soort,LEN(Soort)-FIND("\",Soort))) -

FIND("\",(RIGHT(Soort,LEN(Soort) - FIND("\",Soort)))))


I have not reviewed these functions, I just know that they work.
Maybe it is possible to get the results in an easier way. Feel free to share it with us.

A client asked me if we could group items in a list on a part of a textcolumn.

The text in the column looked like this:

categories per pc/ 106.032

categories per pc/ 106.033




I was supposed to make a view that showed that was grouped by pc name, only the pc name was not to be found seperate in any column. Instead it was a piece of the text in an existing field.It was the last 7 characters of the column.

So I googled and quickly and ended up on this website: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx

There are all functions and operators on fomulas documented. I created a calculated field called PC and inserted this funcion:

=RIGHT(Categories,7)


In named this new field PC and grouped my view on this field. The possibilities in calculated fields have more possibilities then I thaught.

How to group a list or library by month if you have a field containing Dates?

Simple, create a calculated field in your list or library that returns a string.

Use this code: =TEXT(Date,"yyyy - ")&TEXT(Date,"mm")&TEXT(Date," (mmmm")&TEXT(Date," yyyy)")

Now group by this field and that's it!

You can find everything on functions that you can use in calculated fields on: http://office.microsoft.com/en-us/sharepointtechnology/HA011609471033.aspx