I have a DVWP that I need to set up a complex filter on.

It WAS all set - grouped by category field, sorted by item title, then filtered on 2 other fields (year & quarter). Then I was given another requirement - that there might be multiple items per the same year and quarter, and I need to display only the most "recent". I can't make the assumption that the users are actually going to create them in order, so I'll need to use the extra "month" field (numeric, 1-12, sometimes null where appropriate).

Is there a way to say "Display all of the items for this year+quarter combination, but sort additionally by the Month field and leave out any duplicates"?

I should note that the month field would not actually be displayed on this DVWP.

  • Did you ever find the solution to this? If yes, could you post the answer?
    – Kit Menke
    Jul 29, 2011 at 20:57
  • I don't believe so. The project has gone stale due to time constraints so I haven't looked into it too much further.
    – elorg
    Aug 11, 2011 at 17:40
  • This can be done with a little XPath trickery, but I think I'd need to see the schema of your results set, but hard to visualise in the question as it is for now.
    – James Love
    Oct 3, 2011 at 11:11
  • Did you considered building calculated columns beforehand, that could extract month, or quarter and use instead those columns for sorting and grouping? Oct 29, 2011 at 14:27

2 Answers 2


I might take a look at calculating the year, quarter, and month from one date field. After that, it's just a matter of sorting and putting an item limit of "1" on the DVWP.

  • Filter = Display this year/quarter
  • Sort = By Month, Descending
  • Item Limit = Display only 1

If you just need the most recent, "duplicates" is irrelevant.

  • Calculate Month: =MONTH([Date Field])
  • Calculate Year: =YEAR([Date Field])
  • Calculate Quarter: =IF(AND(MONTH([Date Field])>=1,(MONTH([Date Field])<4)),"1",IF(AND(MONTH([Date Field])>=4,(MONTH([Date Field])<7)),"2",IF(AND(MONTH([Date Field])>=7,(MONTH([Date Field])<10)),"3",IF(AND(MONTH([Date Field])>=10,(MONTH([Date Field])<=12)),"4")))

In the XSL for the web part, use a filter in your XPath. Like such:

<xsl:for-each select="/dsQueryResponse/ListName/Rows/Row[(@Year) = $year_Paramater and (@Month) = $month_Parameter and (not(@MonthYearCom = preceding-sibling::Row/@Model_x0020_Number))]">

Then you would have to inject the "year_Parameter" and "month_parameter" into the parameters to compare them.

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.