Skip to main content

Cloud

Content Query Web Part – Sort Order from a Calculated Column

​Here’s a quick way to implement custom sort functionality in a Content Query web part. Since the out-of-the-box options only offer ascending or descending alphanumeric sorting, you can use a Calculated Column to provide the necessary logic.
For example, say you have a list called ‘Defects’ that has the following two Choice fields: ‘Impact’ and ‘Status’.
Impact = {“Red, “Yellow”, “Green”}
Status = {“Open”, “Closed”}
The requirement is for the  Impact field to be sorted in the following order: “Red”, “Yellow”, “Green”. All “Open” items should appear before the “Closed” items.
So what to do…?
We can use a calculated field (that returns a Number) to do the work for us. The idea is to assign each possible condition with an integer value.  The higher the number, the higher the sort order.
First, create a Calculated field.  I called mine ‘Sort-Value’.
Calculated-field
Next, write a formula to assign each condition a numerical value. I used a combination of ‘IF’ ‘AND’ operators.  More information on how to use calculated formula operators can be found here.
Calculated-field-calculation
Here’s a closer look:
calculation
You can now use the Calculated column to sort the list items. If anyone knows of a different way to accomplish this, please leave a comment below.

Thoughts on “Content Query Web Part – Sort Order from a Calculated Column”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Steven Mierop

As a Lead Technical Consultant at Perficient, I've had the pleasure of designing and delivering custom solutions on SharePoint 2007-2013. I have a strong passion for web application development and the .NET framework. Over the past three years, I have implemented a variety of SharePoint and .NET solutions for clients in a wide range of Industries such as Health Care, Insurance, Pharmaceutical, and Publishing.

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram