Aggregating Items From Past 7 Days in SharePoint 2010

A while ago I wrote a post on how to aggregate items from ‘the last 7 days’ using the Content Query Web Part in SharePoint 2007, which involved exporting the webpart and overriding the CAML query. Now in SharePoint 2010 it’s a much easier process to achieve the same result.

The CQWP now includes additional filters such as the PageQueryString and PageFieldValue filters. Also they have helpfully added the ability to provide a whole number value for date fields which will correspond to Today +/- the number of days. This is all helpfully explained in the inline help in the webpart properties pane (below).

CQWP Help Text

We can now use this feature to setup the filters of our query to return items only from the last 7 days, in this example to return Article Pages. Constructing the filter for items in the last week we need to return pages with a date that is:

  • greater than today minus 7 days AND
  • less than or equal to today

  CQWP Date Filters

This straight-forward query then gives us only the articles that we want to see in the results of the CQWP. Turning the default aggregation from this:

 CQWP Results

Into this:

CQWP Filtered Results

As an aside, to help with testing I needed to get the article date returned in the results. This was quickly achieved without having to edit any XSL by using another of the new additions to the Content Query Web Part in SharePoint 2010 – Slots. This simply allowed me to specify a particular field that I wanted to use as the description text in the default presentation style.

share and enjoy
  • Print
  • Twitter
  • Digg
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>