Follow up to this question: CAML is ordering by content type even though not specified

I have the following query:

            <FieldRef Name='_ModerationStatus' />
            <Value Type='ModStat'>0</Value>
            <FieldRef Name='ContentTypeId' />
            <Value Type='ContentTypeId'>0x0120</Value>
            <FieldRef Name='Number' />
            <Value Type='Lookup'>0</Value>
            <FieldRef Name='ID' />
            <Value Type='Counter'>0</Value>
     <FieldRef Name='NumberOf' LookupId='True' />
<GroupBy Collapse='True'>
    <FieldRef Name='NumberOf' />

It works well, however not every list item has a value for the column 'NumberOf', so when my results are returned, with the numbers grouped at the bottom of the results, like this:

enter image description here

Is it possible to have the opposite, where the ordered 'NumberOf' column with numbers are first (ie. 2,3,5) and null values afterwards?

2 Answers 2


Try changing your OrderBy to Descending:

  <FieldRef Name='NumberOf' LookupId='True' Ascending='False' />
  • if you put more details about it really great.
    – Waqas Sarwar MVP
    Jun 11, 2014 at 21:05
  • This works, but the numbers would be in descending order. I essentially would like to have the Order By clause return the data so that the 'null' values in the 'NumberOf' column are after the 'not-null' values. Jun 12, 2014 at 13:16

I think the best you can do is to order it by the NumberOf field descending (Ascending='False'), so you'd have 5, 3, 2, null. In either case, you'll need logic after calling this query to resort the result set to meet your needs.

Your Answer

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

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