Adding an aggregated total to the top of a stacked column chart sounds simple enough. It’s a couple of clicks in Excel. In MS CRM 2011 however, it is a different story. You would have to add an additional series to the chart, which then calculates and displays the total. But Stacked Column charts in MS CRM 2011 do not support multiple series.
But that does not mean it is not possible. This CRM chart show us the aggregated total value of each of our pipelines, stacked by the pipeline phases, for each of the types of purchase processes.
So how did I create this chart? First, I need a chart with a series for each of the 4 pipeline stages, and one for the total. Then I display the series in the chart so they look like a standard stacked column chart. The total on top is a point chart type. The drawback here, is of course that all the possible series needs to be known so we can include them in the chart. In this case, all the series are each phase in the pipeline.
Since the user interface in MS CRM 2011 for creating charts does not support multiple series for stacked column charts, we need to create something else as our chart XML base and work off that.
I will use the UI to create a normal column chart and add all the series I need.
In this case a column chart with 5 series.
1 for each of the 4 stages in the pipeline (Develop, Qualify, Propose, Close) plus 1 extra series for the total.
I want to see how my pipelines looks between the different types of Purchases Processes, so I’ll pick “Purchase Process” as the category so I get that on the X axis.
All the series I have added as a standard column chart.
Now I’ll export the chart xml and get to work. (Full chart XML samples are available at the bottom of this post)
CRM 2011 might add some references to a secondary Y axis in your XML. If that is the case, remove these first.
Rename the series in the Chart XML
I’ll start out by renaming all the aliases to something more sensible and easier to work with.
Original XML
Chart XML with renamed aliases
Now it’s much easier for me to see which alias represents what data. I have “Purchase Process” as the category, the name for each pipeline phase, and the aggregated total at the end.
Change the Series Chart Types
Next I’ll change the first 4 series for the pipeline phases from ChartType=”Column” toChartType=”StackedColumn”.
The last series for the aggregated total will need the following changes;
- ChartType=”Point”
- IsVisibleInLegend=”False” – don’t need to see “Total” in the legend
- IsValueShownAsLabel=”True” – YES, this is the whole point of this chart
- LabelFormat=”#,#,#” – no need to see decimals on the total
- MarkerColor & MarkerBorderColor=”Transparent” – we just want the total amount – no need to see a marker also
- The font I increased to 14px so it stands out more
Let’s do a quick import of the chart xml just to check what it now looks like in CRM.
We can see the total amount in the larger font, but the different pipeline phases are also showing the aggregate amount.
Let’s add a filter to each of the series in the fetchcollection, so they only show the correct amount for each phase.
Filter the series for the Pipeline Phases
Here’s the original fetchcollection.
I’ll add a filter to each of the series by creating a self-referential <link-entity>. This will allow me to make sure each series only sum up the value of the Opportunities, specific to its phase. The easiest way to get the filter properties is by creating them in Advanced Find and export the FetchXML.
Each attribute will get a <link-entity> and <filter> added as follows.
<
link-entity
name
=
"opportunity"
from
=
"opportunityid"
to
=
"opportunityid"
link-type
=
"outer"
>
<
attribute
alias
=
"qualify"
name
=
"estimatedvalue"
aggregate
=
"sum"
/>
<
filter
>
<
condition
attribute
=
"stepname"
operator
=
"eq"
value
=
"1-Qualify"
/>
</
filter
>
</
link-entity
>
|
Here’s a part of the fetchcollection with filters added for each attribute for the pipeline phases. The last attribute I’ll leave without a filter as we do want the total on that one.
Time to import the XML and have a look.
Chart is now filtered and stacked properly for each series and there’s an aggregated total on top.
Adjust Chart Axis, Legend and Colors
It works, but we can make the chart look a lot easier to read and understand.
I’ll make the following changes:
- IsValueShownAsLabel=”false” on all series except the total.
- Add LegendText to all the series except the total
- Add Color to each series – I’m going with increasingly darker shades of blue in this case
- Add Format=”$#,#,k” to the LabelStyle for a shorter label on the Y axis
Last, I’ll reverse the series in the legend, because MS CRM 2011 automatically reverses it on stackedcolumn charts. In other words, I reverse the reversed order so it reads 1-2-3-4 instead of 4-3-2-1.
One final import of the CRM chart XML and here’s the result.
A couple of notes:
- Bonus: Even though no Opportunities are in phase “4-Close” we still see it in the legend
- Filtering in the XML can be tricky – it’s your job to make sure everything relevant get’s accounted for
- This approach allow you to add colors directly in the Series, which can be a lot easier than using the PaletteCustomColors
- The Series have to be listed in the exact same order in the presentationdescription as they do in the measurecollection
- The User can still hover the mouse over the chart to get the exact value of each pipeline phase in the tooltip
How about an Aggregate Total on top of a Stacked Bar Chart?
The same approach can be used for bar charts. All the chart types need to be a Stacked Bar for the pipeline phases and then a regular Bar type for the total, which then have to be made transparent. (XML sample included at the bottom of post)
Hope you enjoyed this post.
If you did, please follow me on Twitter for CRM Chart updates Follow @crmchartguy
Chart XML Samples
These chart xml samples are for reference only and not intended for use in a live environment without thorough testing.
They were created on a Microsoft Dynamics CRM 2011 trial with only the sample data added. The only addition I made to the sample data, was adding values to the Purchase Process field on the Opportunities.