I have a customOrder column in list, its ordered by that number ascending.

I want all null values listed after items that has value in customorder. I wish all null values would be ordered asc as default but not So how can I do that with caml query is it possible?

as you see below all items null values listed top of the table I want them come after items that have value in customorder

enter image description here

  • Are you using server side code or JavaScript to get items from list ? Commented Mar 9, 2017 at 18:35
  • Server side. in C# Commented Mar 9, 2017 at 19:34

1 Answer 1


Unfortunately this is the default OOTB behaviour of CAML query using SharePoint.

To ignore get null values at the end, you should create a calculated column in the list which will calculate if the sort column is empty or not. The formula of that would be =IF(ISBLANK([CustomOrder]),0,1) . After that, you should sort CAML by these 2 columns as below:

   <FieldRef Name='CalculatedColumnInternalName' Ascending='False' />
   <FieldRef Name='CustomOrder' Ascending='False' />

To create calculated column - follow this link Create calculated column and use the formula I mentioned.

Reference - Ignore Null Values in OrderBy Asc While creating CAML Query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.