Update 4/6/2017: Post updated to apply to all versions of Dynamics CRM from CRM 2011 to Dynamics 365.
The Order of which a series is displayed can be a little tricky to work with. If no order is defined in the chart, the chart will display your data according to the sort order defined in the View that you are using. So excluding the order clause from the chart can give you a more dynamic way of adjusting your charts, as you won’t need to do XML customizations. Relying on the view also limits your sorting options to name fields or dates. I.e. you cannot use the View settings to order on aggregated fields.
However, it is often needed to specify one or more order clauses to make sure your data is presented properly.
To specify how data is ordered, or sorted, we utilize the Order clause in the fetchcollection in the XML.
In this example, I have added two order clauses to a case chart.
The first line is the primary sort order and the following line is the secondary sort order. That way you can control the sort orders by adding the order clauses in the correct order. That was too many “orders” for one sentence.
- Order clauses can only be set for fields on the primary entity
- When using option sets as the basis of a series, the series get ordered according to the value of the option set and not its label. Note the option set ordering varies between CRM versions. There was a bug in previous versions that got fixed in the year 2014 and allowed proper sorting of option sets according to the value. Now in Dynamics 365 it sorts according to the label.
- More info on MS website can be found here http://msdn.microsoft.com/en-us/library/gg309565.aspx#orderby_aggregate
- If you need to sort on a linked entity, please see this blog post
Hope you found the tip useful. As always please sign up for my newsletter and follow me on Twitter. Follow @CRMChartGuy