Calculated column: week number

I decided to organise a small project by using a SharePoint task list on a Office 365 project site. I figure that if it gets too complicated, I can always just open the entire thing in Microsoft Project.

I realized fairly quickly that seeing week numbers in the list was a valuable thing:

  • Group the tasks by week
  • See the total number of estimated hours per week

I created a calculated column and used the comments on this page, Group A List by Week Number. I ended up changing the formula a little bit – there are some activities in December and some in January, so I wanted to see the year, as well as the week number for sorting purposes.

My final formula:

=YEAR([Start Date])&"-"&If(Int(([Start Date]-Date(Year([Start Date]);1;1)+(TEXT(Weekday(Date(Year([Start Date]);1;1)-1);"d")))/7)=0;52;Int(([Start Date]-Date(Year([Start Date]);1;1)+(TEXT(Weekday(Date(Year([Start Date]);1;1)-1);"d")))/7))

The final result looks like this:


You can see an error on the third line: that’s because [Start Date] is empty on that line, so the week number could not be correctly calculated. I just wanted to get on with the project planning and not spend more time on the formula.

Once you have the week number in place, you can easily make views like this one, where I grouped by Week and then summed up the total hour estimate:


The formula has the following considerations:

  • Weeks begin on Monday
  • Working with Swedish regional settings – you may need to change around a few periods, semi-c0lons, etc.

Adding a code snippet to page content on SharePoint 2013

Note: this post is written specifically for SharePoint 2013.

Sometimes it is necessary to add a snippet of code to just one page. Examples could be:

  1. Alternative CSS for just that page, i.e. to style a specific element
  2. Add a snippet of HTML and/or JavaScript, such as for a Google Maps or Youtube embed
  3. Add a piece of CSS to hide the left navigation on specific pages
  4. Add the Open In Explorer Link to a page

There are technically a number of ways to achieve this:

  1. Paste the code directly into the page contents (does not work)
  2. Paste the code into the the HTML source of the Content Editor Web Part (can work, depending on SP version and code)
  3. Use the Embed command  (can work, situational)
  4. Save the code in a text file, save it somewhere on your SharePoint site collection and call the text file via the Content Editor Webpart (my preferred method)

Option #4 is my favorite for a number of good reasons:

  • You can save the code centrally and then call it from multiple places without needing to replicate it
  • By saving it centrally, you only need to update it once if there are changes or updates
  • By saving it in the content database, you can access it from SharePoint Designer or similar, meaning you do not need to keep downloading-updating-uploading
  • It works consistently across all versions of SharePoint from SharePoint 2007 up to Office 365

For this example, I will be using a simple JavaScript which shows copyright information, in this case from 2010 to the current year. This allows the copyright to be kept up to date:

<p>All right reserved  &copy;
var cur = 2010;
var year = new Date(); 
if(cur == year.getFullYear()) year = year.getFullYear(); 
else year = cur + ' - ' + year.getFullYear(); 

Option 1: Paste the code directly into the page content

You can paste the code directly into the page content.


However, once you save the page and view it, you will see that SharePoint does not realize that it is code it needs to render in some way.

Conclusion: do not place code directly in the page content as it does not work.

Option 2: Edit source in rich text area / CEWP

In most content editor webparts and all rich text areas, there is a button in the ribbon called “Edit source”. This is great for quick fixes when content has gotten out of hand. In older versions of SharePoint, you could also use it to embed extra code.

Edit Source

You can easily paste your code straight into the Edit HTML window.

However, once you save, SharePoint lets you know that the code that it does not approve of has been stripped.


In this case, some of the embedded code has been stripped out.


Sometimes SharePoint will strip out all of it and sometimes it will only strip out parts which can cause an odd result. When it doubt, check back into the HTML source to see what has happened with your code and if it is still 100% intact.

Conclusion: while this used to work under some older SharePoint versions, it is generally not a reliable solution for SharePoint 2013.

Option #3: Using the Embed command

SharePoint 2013 includes an Embed command in the ribbon which can be great for adding code snippets to your page:


After clicking the command, you are prompted to insert your code and given a preview:


SharePoint creates a Script Editor webpart on the page for you. It even includes an “Edit Snippet” button, so you can go back and edit the code later.


The JavaScript is being displayed correctly in the webpart and also on publishing the page.

Conclusion: in my experience, this works but is dependent on the complexity of the code. Test well before using.

Option 4: save as a text file, call via CEWP

I have saved the JavaScript into a file called copyright.html. The file extension can help SharePoint determine how to parse the code when it is called, but you may need to experiment depending on your code – I have had good results from using txt, html and js extensions in the past.

Here is the file in Notepad++:


In this demo, I uploaded the HTML file to the document library on the same site as the page we are working with.


Tip: I tend to use the following rules of thumb as to where to upload these kinds of files:

  1. Think about if you want to save it in the standard Document library, or if you want to create a dedicated document library called “Scripts” or similar
  2. If the file will be called from just one single site, save it on the site
  3. if the file will be used across just one site collection, consider saving it at the root of the site collection or in the Style Library of that site collection (i.e. Styles/Scripts)
  4. If using across multiple site collections, choose the most logical place for it, i.e. on a root site collection

Next, place a Content Editor Web Part (CEWP) on the page and edit the webpart settings. At the top, add the link to the file and click “Apply” to save the changes.


The content should immediately display in the CEWP on the page.


Tip: if  you wish to use the same webpart in many places, you could export the configured CEWP and import it as a custom webpart. You can then place it on a page and it will already be configured for you.

Conclusion: this is my favorite method due to the central storage of the files, ease of editing the files and reusability.

SharePoint social and favorites in Outlook


One of my current clients works with the Outlook addon for copying emails and documents to SharePoint.  I believe it is a neat and useful tool which can complement OneDrive for Business.

I recently got a request to allow users to create favorite libraries/sites on SharePoint and have this list be synced with

Summary does not seem to have a way access SharePoint 2013’s “follow” functionality. This may be possible with registry edits or custom code, but I have not found the solution yet.

However, can sync with the My Links list, which is part of the User Profile Service from SharePoint 2010 and onwards. Libraries can be added to this via the “Connect to Office” button. It is also possible in MOSS 2007.

SharePoint 2013 “follow”

In SharePoint 2013, new “follow” functionality has been added, allowing users to follow People, Documents, Sites, and #Tags. It is then possible to see updates via the newsfeed on your My Site.


The idea was to allow the client to select which sites they would like to follow, then use that information for two purposes:

  1. Display a list of favorite sites on the landing page
  2. Input for the “favorites” in the Outlook client

The first goal turned out to be fairly easy – once I found out that the “Site” content type on the My Site is not actually searchable. There is a premade REST/jQuery soution available via I Am Following which worked beautifully.  The page includes a link to the code download on Codeplex.

The second turned out to be quite a bit harder. I spent a lot of time investigating the Harmonie documentation and tried everything I could find, including using registry edits for site propogation in the favorites. That site propagation turned out to only work for the enterprise client, not the free client and was really more for prepolating the client with specific sites. I was not able to get the registry edit “SyncFavoritesWithMyLinks” working, as described on Add My Links to the sites and favorites lists.

Conclusion: there is currently no good way to sync the followed content on SharePoint 2013 with Harmonie.


My Links

After lots of frustrating, I was rereading the documentation on the Harmonie site and came across the following:

When working with SharePoint 2013/2010, adds the document libraries defined via the SharePoint 2013/2010 ribbon button Connect to Office to your favorites list.

Source: Favorite Locations

My Links is the old bookmarking functionality in SharePoint, used in SharePoint 2007 and 2010. It was replaced by the follow functionality in SharePoint 2013. It requires the User Profile service to be enabled, as it is a per-user list.  Clicking the button adds the current library to My Links.

You can access this, exactly as the documentation states, via the Library tab of document libraries:


This same functionality is used to create shortcuts in Microsoft Office applications for opening and saving documents.

To make this document library be added to the favorites in your client, follow these steps:

  1. Click the “Connect to Office” button in the applicable library
  2. Restart Outlook (the list is checked on application startup)
  3. Find the new list in your favorites in

You can maintain the My Links list by clicking on the dropdown on the Connect to Office button. You’ll see that the list looks pretty much as it did in SharePoint 2007.



Sources Favorite locations (in Outlook)

Office Blogs: Following in SharePoint 2013

Thanks go to Wictor Wilén for his tips

SharePoint Saturday Oslo: Recap @spsoslo

Whew! SharePoint Saturday Oslo 2014 was a blast! Thank you again to the organisers for a wonderful job!

It was my first time speaking at a SharePoint Saturday. I’ve done plenty of speaking internally at companies, clients, etc., but this felt very different. I learned a ton (count on the internet going down and you will never be surprised) and met lots of fascinating people.

Continue reading

Adding an image + link via calculated column on a list with HTML (Directory List Solution)

I was working on a document management system, where each client had its own site collection and projects were subsites under that site collection. I needed a way to show a list of available site collections from a main landing page.  This needed to show all site collections, no security stripping and search rollup was not an option at this time. The easiest way then is to create a list that acts as a directory – just add the sites to the list manually.

The problem was the link to the sites. How best to do this?

Option 1: Hyperlink site column

Adding a hyperlink site column is easy. You get a clickable result in your field display.

The tricky part is dealing with the fact that a hyperlink column consists of two fields: the web address and then the description.


If you do not fill in a description, the URL is displayed when you view the item.


This approach has a few issues:

  • Showing a text like “Link” is not very nice looking.
  • When an end-user fills in the item, they may not be consistent with the result. You could add a description to the field, but this is still not foolproof.
  • Even though the link is blue, not everyone will realize that you need to click the text to open the site – many people will still try to click the title and then just open the item.  This leads to frustration.

Option 2: Creative use of calculated column

You can use a calculated column to display the link as an image, i.e. an arrow or something that is very obviously a link – how about something like this?


By choosing to use a calculated column, we have ensured that anywhere the column is used, the arrow will be displayed. This means that it will work in any view, any webpart, etc.

*** Update 2017-07-21: This worked on SharePoint 2013 and SharePoint Online until sometime this spring. When using SharePoint Online, it now only works in classic mode – it has been disabled in the new mode.


To replicate, follow these steps. The column names are not important, they are just suggestions.

  1. Upload an image to SharePoint, i.e. in your site assets library
  2. Create a new (site) column of the type “single line of text”, and call it “Site URL
  3. Create a new (site) column of the type “calculated column” and call it “Site Link” or similar
  4. Use the formula as stated below, adjusted for your site and column names –
  5. Change the output of the column from “single line of text” to “number”
  6. Save the column and enjoy



The formula I used is as follows:

=IF(ISBLANK([Site URL]), "URL Missing", ("<a href="&[Site URL]&" target='_blank' alt='Open site in new window'><img src='/SiteAssets/link.png' style='height:20px; width:20px;' /></a>"))

Broken down, it has a few interesting elements:

  • IF(ISBLANK([column name]), “URL Missing” – if the column with the URL is empty, it will show this text. If you leave off this structure, then the calculated column will simply be empty. You can also change the “URL Missing” text to whatever you would like, i.e. “Please fill in a URL”.
  • A hyperlink is created based on the value of the Site URL column
  • The link opens in a new window (this is specific to my example, as I expect a new window to be more useful for these users)
  • Link to the image
  • Set the image height – I found 15-20 pixels fit nicely into the column. You could also include a class from your CSS.

Tip when editing formulae in calculated columns: use Notepad++, as it will help you see when brackets are closed.  Just make your changes in Notepad++, then copy them into the edit column window each time – this will make it far easier to work with.


Display as HTML

One of the coolest things about this solution is that generally, calculated columns cannot be rendered as HTML. Technically speaking, the contents of the column should just be displayed as plain text. Yet, here we are, with an nice arrow image being displayed and the link working beautifully. The trick is changing the returned datatype from single line of text to number. Once you do that, then the contents are rendered as HTML.

Credit for this solution goes to Danny Engelman at ICC – HTML in a Calculated Column / Field of a SharePoint View.

Site columns and content type hubs

In the real world solution, both the Site URL and Site Link columns were site columns, attached to a content type called Client Directory. The columns were also reused for a similar construction in a Project Directory custom list, which showed the subsites under each client site collection. Using a content type hub, these columns were replicated to each site collection and we were able to build a similar Project Directory in exactly the same way: simply fill in the URL, display Site Link column. This made the solution incredibly flexible and reusable.


HTML in a Calculated Column / Field of a SharePoint View

Calculated column for priority on a SharePoint list

I’m currently working on a project where we needed to assign a priority to issues based on impact and urgency. You could always let users figure this out for themselves, but it’s much better to automate it when there are clear definitions for each value and a table which translates the impact and urgency to priority.

Continue reading

Calculated column for priority

I’m currently working on a project where we needed to assign a priority to issues based on impact and urgency. You could always let users figure this out for themselves, but it’s much better to automate it when there are clear definitions for each value and a table which translates the impact and urgency to priority.


My first thought was: “Sure! I’ll do that! It’ll be simple.” Then I found myself looking at the calculated column formula screen and realized that it had been a long time since I had needed this knowledge.

The first limitation is that SharePoint only allows for up to 7 nested IFs. I broke the solution up into four calculated columns:

  1. Priority – Very Urgent
  2. Priority – Urgent
  3. Priority – Not urgent
  4. Priority – calculated

The first three columns calculate the correct priority value based on each urgency line. If the urgency is very urgent, the formula checks to see what the impact is and then sets the field value to the priority listed in the table.  If the urgency in that issue does not match the formula (i.e. if the urgency is not very urgent), the field value is set to “N/A”, as that urgency is not applicable.

/* Very urgent */
=IF(AND(Urgency="Very Urgent",Impact="Critical"),"1",
IF(AND(Urgency="Very Urgent",Impact="High"),"1",
IF(AND(Urgency="Very Urgent",Impact="Medium"),"3",
IF(AND(Urgency="Very Urgent",Impact="Low"),"3",
IF(AND(Urgency="Very Urgent",Impact="Very Low"),"4","N/A" )))))

/* Urgent */
IF(AND(Urgency="Urgent",Impact="Very Low"),"4","N/A" )))))

/* Not urgent */
=IF(AND(Urgency="Not Urgent",Impact="Critical"),"2",
IF(AND(Urgency="Not Urgent",Impact="High"),"3",
IF(AND(Urgency="Not Urgent",Impact="Medium"),"3",
IF(AND(Urgency="Not Urgent",Impact="Low"),"4",
IF(AND(Urgency="Not Urgent",Impact="Very Low"),"4","N/A" )))))

To tie it all together, the Priority – calculated column looks at the values of all three columns and displays whichever one does not have the value “N/A”. If none of them have that, then the column displays the text “error”.

/* Final calculation */
=IF([Priority - very urgent]<>"N/A", [Priority - very urgent],
IF([Priority - urgent]<>"N/A", [Priority - urgent],
IF([Priority - not urgent]<>"N/A", [Priority - not urgent],
"Error calculating priority")))

To test, I showed all 6 applicable columns in a view:


You can see that because the urgency was very urgent and the impact was critical, a 1 was filled into the priority – very urgent column. When the Priority – calculated column did its work, it copied over the 1 from the priority – very urgent column.

Creative use of the Reusable Content option for styling on SharePoint

I have rarely seen clients use the Reusable Content option. Occasionally it will be used to add a disclaimer to a page – but often that’s best placed in a page layout for a specific page type anyway. There just doesn’t seem to be much of a use for it, though I’ve always wondered if there could be a really useful application.

In a recent project, Daniel Gustafsson found two really cool uses for it: adding a floating image to page content and adding numbered bullet points which are highly styled. These are by far the most interesting uses I have ever seen for the Reusable Content, which is why I asked Daniel if I could share them with you here.

Continue reading

Creative use of the Reusable Content option

I have rarely seen clients use the Reusable Content option. Occasionally it will be used to add a disclaimer to a page – but often that’s best placed in a page layout for a specific page type anyway. There just doesn’t seem to be much of a use for it, though I’ve always wondered if there could be a really useful application.

In a recent project, Daniel Gustafsson found two really cool uses for it: adding a floating image to page content and adding numbered bullet points which are highly styled. These are by far the most interesting uses I have ever seen for the Reusable Content, which is why I asked Daniel if I could share them with you here.

This example is done using SharePoint 2013, but should work for all versions. Be careful with the HTML5 on older versions of SharePoint, though. You will need to add your own CSS.

This article will discuss how to handle an image with float left:

And it will also handle numbered bullet items:


What is Reusable Content?

Reusable Content allows end users to save snippets of commonly used text or HTML which can then easily be put onto a page.

All Reusable Content is saved into one list per site collection, always saved at the root in the list Reusable Content.


Reusable content can be anything you might need to reuse:

  • Byline
  • Disclaimer text
  • Standard piece of HTML
  • “About me” text

Once a piece of content has been added to the Reusable Content list, it can be added to a page by clicking the Reusable Content button in the ribbon and then choosing the item from the list.


Reusable Content items come with an interesting feature called “Automatic Update”. If you turn this on for an item and update the content, it will update everywhere the Reusable Content has been placed. this can be extremely useful in many places. In the following two examples, it must be turned OFF for the functionality to work correctly.

Image float left

Image float left inserts an image with text possibilities into the page, floated left:


The default image is configured as a basic placeholder, giving the user something to click. Once the image is selected, you can choose a new image via the Replace Image option in the ribbon.


The texts can be replaced just by clicking on them and changing them to whatever the user needs. The texts also keep their formatting, as long as the user doesn’t delete too much of the reusable content item.

Configuration in Reusable Content List

Note: automatic update must be set to no.

Reusable HTML (remember to edit HTML source when editing):

<figure class="float-left box-story"><img alt="image" src="/Common-Image-Library/placeholder.jpg" _moz_resizing="true" style="width: 300px; height: 300px;"/><figcaption>
<header>Header for box story</header>
<p>“Box story body text”</p> </figcaption> </figure>

Bullet points with header

Sometimes the default unordered list in SharePoint is overly boring, even after styling it. The developers in this project came up with a much cooler way to display the content:


It’s a little fiddly in the implementation and later changes – adding something in between the current header 2 and header 3 is difficult, for example. However, when you are looking for a very stylized front-end website, it may very well be worth it.

This content actually consists of two pieces of Reusable Content: first, the Numbered List Item Wrapper is placed. Afterwards, the Numbered List Items can be placed into that wrapper.

Numbered list wrapper

Note: automatic update must be set to no.

Reusable Content HTML:

<div class="numbered-list">MARK TEXT and add reusable content numbered list ITEM</div>

When this is placed on the place, it simply shows the text shown in the div. To use it properly, select the text and then choose the numbered list item from the Reusable Content.

Selecting the text simply ensures that the actual list items are placed inside the list wrapper div.

Numbered list item

Note: automatic update must be set to no.

Reusable Content HTML:

<div class="numbered-list-item">
   <div class="numbered-list-item-content">
      <header>Numbered item with header</header>
      <p>Body text for numbered list item</p>

Add this Reusable Content item to the wrapper as described below, simply adding more bullets until there are as many as you would like that. Afterwards, edit the headers and texts to match what is required.

CSS for the numbered list reusable content

/* ------------------------------------------ */
/* ------------------------------------------ */
.numbered-list {
    counter-reset: numlist;
    border-top: 1px solid #CBC7C2;

.numbered-list-item {
    border-bottom: 1px solid #CBC7C2;
    padding: 15px 0 4px 1px;

.numbered-list-item:before {
    counter-increment: numlist;
    content: counter(numlist);
    -webkit-border-radius: 999px;
    -moz-border-radius: 999px;
    border-radius: 999px;
    width: 10px;
    height: 10px;
    padding: 8px 10px 12px 11px;
    background: #b4a76c;
    color: #fff;
    text-align: center;
    font: bold 14px/1 HelveticaNeueSerif, serif;
    font-size: 1.16667rem;
    float: left;
    margin-top: -5px;
.numbered-list-item-content {
    margin-left: 42px;
    padding: 0 0 0;
.numbered-list-item-content header {
    font: bold 15px/1.2 HelveticaNeueSerif, serif;
    color: #404040;
    font-size: 1.25rem;
    font-weight: bold;
    margin: 0 0 10px 0;
.numbered-list-item-content p {
    margin-top: 0;

SharePoint Saturday Stockholm 2014

After all of the dust has settled and I have caught my breath, I can say that the first SharePoint Saturday Stockholm was a success!

Speakers and organizers SPS Stockholm 2014

The final stats as tweeted by @SPSSthlm

210 registered
183 attendees
27 no-shows :(
78 on waiting list
20 speakers
3 organizers
10 volunteers
10 sponsors

Thank you, once again, to everyone to participated, spoke, helped out and generally made it an awesome event!

Thanks again to my co-coordinators, Matthias Einig and Erwin van Hunen.

You can still see the site  at  Note that many of the slides and videos of the sessions are available via the sessions page.


I’m already looking forward to next year!