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.
Notes:
- 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
[…] Modify the order of the colors Order the data so the Priority series are always colored the same […]
Is it possible to sort a chart by the x axis? For example if my a axis values are 1-10 I want them to appear in that order. At the moment group 3 has a higher count than those records in group 1 so 3 appears first.
Thanks
I have an issue with chart sorting. Here’s my fetch:
The industrycode is actually a picklist, and it does not sort correctly. In fact, it doesn’t seem to sort logically at all. The results are neither alphabetical nor sorted by count. It makes no difference whether or not I leave the “order” clause in the fetch statement.
I see this same behavior for any chart using a picklist as the series. Charts using other types of values sort correctly.
Have you seen this before?
[…] Order clause has been added to sort the chart […]
I’m trying to sort an Opportunity Product view. I am able to use the view sort to get my first sort correct. The problem is coming from an Opportunity column I added to the view that is for the “stepname” or Pipeline Phase on the Opportunity entity. I see in your blog that you cannot sort on related entities, is this still true? My problem is our pipeline chart is sorted by fiscal period on the bottom axis, and I have stacked columns to show the pipeline phase by color, but one week the “90%” stage will be blue, then next week it’s yellow, or another color. Frustrating and it’s hard to visually read the chart without using the legend. Any help would be awesome. Thanks!
Sort the column you want on the view. That will translate over to the chart.
Any other options when the column in question is on a parent table and not shown for sorting in the View?
You have to configure the sorting on the column on your choice within the view the chart is based on.
Sorting by aggregate using XML http://us.hitachi-solutions.com/2011/06/02/crm-2011-dashboard-sorting-a-chart-on-the-aggregate-value/
That is how I sort my first level. Sorting the 2nd level is impossible without editing XML because my 2nd criteria is from another entity. Thanks for the suggestion though.
Struggling to figure out how to sort by fiscal period in my grouped goals (by custom region field) chart… see below: Keeps sorting by the following – Q2, Q4, Q3 :/. Any help?
Regional Quarterly Progress (Fiscal Year)
goal
false
[…] Modify the order of the colors Order the data so the Priority series are always colored the same […]
Is there a way to order by a “calculated field”?
I have 2 currency fields on an Opportunity that are being added into a calculated field. When I create a chart that
– groups by customer
– summarizes the calculated
I cannot sort by the calculated field nor ad a top 10 filter. Can you help me with this?
i want to create a stacked barchart for monthy pipeline and comitment. The problem is that i have in one colum values that are either empty or “yes”. However i change the sorting in the view or in the diagrams xlm, i cant get the empty ones to be on top of the “yes” in the chart. do you have any idea?
love your page by the way! helped me out a lot
i want to create a stacked barchart for monthy pipeline and comitment. The problem is that i have in one colum values that are either empty or “yes”. However i change the sorting in the view or in the diagrams xlm, i cant get the empty ones to be on top of the “yes” in the chart. do you have any idea?
love your page by the way! helped me out a lot
Is this a Boolean two option field? I don’t see why that wouldn’t work.
Hi Ulrik,
it is a Picklist with 3 Values: “yes”, “no” and blank if nothing is set. I have filtered the data in the view to only show “yes” or blank.
This is my Code, do you see the error?
”
“
lol, ok Code Posting doesnt work 🙂 sorry….
Is it possible to order a chart based on a field of the underlying view that is not displayed in the chart? Example:
I have a chart that plots Overdue invoices (sum) as a series and Customer (Account) and Invoice Owner as category. Gives me a nice chart that tells me who is overdue, by how much and who on our side is responsible for following up. The problem is that the order seems to be completely random, even though the view is ordered by due date.
How do I order my chart by due date?