Archive for category Aggregate Total

Aggregate Total on top of Stacked Column Charts or Bar Charts in MS CRM 2011

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.

CRM 2011 Stacked Column Chart with aggregate total on top

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.

Chart Designer with all the series and category - CRM 2011 CRM Chart

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

Original Chart XML datadescription with aliases highlighted

Chart XML with renamed aliases

Chart XML with new 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” to ChartType=”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

Changing the series charttypes in the xml

Let’s do a quick import of the chart xml just to check what it now looks like in CRM.

Chart after intial modifications - no filters, all totals

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.

Chart XML Fetchcollection with new aliases

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.

Chart XML Fetchcollection with Filters for each phase matcing the alias

Time to import the XML and have a look.

Chart with Total on Top - Filtered, but with Orignial colors and settings

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.

Cleaning up the Chart by adding colors ot the series etc.

One final import of the CRM chart XML and here’s the result.

CRM 2011 Chart - Stacked Column with Aggregate Total on Top

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)

CRM Chart 2011 Stacked Bar with Aggregate Total on top

Hope you enjoyed this post.

If you did, please follow me on Twitter for CRM Chart updates

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.

Stacked Column Chart with aggregated total

<visualization>
<visualizationid>{C618533F-3784-E211-8B16-78E3B5114607}</visualizationid>
<name>Aggregated Total on top of StackColumn chart</name>
<primaryentitytypecode>opportunity</primaryentitytypecode>
<datadescription>
<datadefinition>
<fetchcollection>
<fetch mapping="logical" aggregate="true">
<entity name="opportunity">
<attribute groupby="true" alias="purchase_process" name="purchaseprocess" />
<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>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="develop" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="2-Develop" />
</filter>
</link-entity>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="propose" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="3-Propose" />
</filter>
</link-entity>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="close" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="4-Close" />
</filter>
</link-entity>
<attribute alias="aggregated_total" name="estimatedvalue" aggregate="sum" />
</entity>
</fetch>
</fetchcollection>
<categorycollection>
<category alias="purchase_process">
<measurecollection>
<measure alias="qualify" />
</measurecollection>
<measurecollection>
<measure alias="develop" />
</measurecollection>
<measurecollection>
<measure alias="propose" />
</measurecollection>
<measurecollection>
<measure alias="close" />
</measurecollection>
<measurecollection>
<measure alias="aggregated_total" />
</measurecollection>
</category>
</categorycollection>
</datadefinition>
</datadescription>
<presentationdescription>
<Chart Palette="None" PaletteCustomColors="55,118,193; 197,56,52; 149,189,66; 117,82,160; 49,171,204; 255,136,35; 97,142,206; 209,98,96; 168,203,104; 142,116,178; 93,186,215; 255,155,83">
<Series>
<Series ChartType="Stackedcolumn" LegendText="1-Qualify" Color="LightSteelBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedcolumn" LegendText="2-Develop" Color="CornflowerBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedcolumn" LegendText="3-Propose" Color="RoyalBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedcolumn" LegendText="4-Close" Color="DarkBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Point" IsVisibleInLegend="False" IsValueShownAsLabel="True" LabelFormat="$#,#,#" MarkerBorderColor="Transparent" MarkerColor="Transparent" Font="{0}, 14px" LabelForeColor="59, 59, 59"></Series>
</Series>
<ChartAreas>
<ChartArea BorderColor="White" BorderDashStyle="Solid">
<AxisY LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorGrid LineColor="239, 242, 246" />
<MajorTickMark LineColor="165, 172, 181" />
<LabelStyle Font="{0}, 10.5px" Format="$#,#,k" ForeColor="59, 59, 59" />
</AxisY>
<AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorTickMark LineColor="165, 172, 181" />
<MajorGrid LineColor="Transparent" />
<LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" />
</AxisX>
</ChartArea>
</ChartAreas>
<Titles>
<Title Alignment="TopLeft" DockingOffset="-3" Font="{0}, 13px" ForeColor="59, 59, 59"></Title>
</Titles>
<Legends>
<Legend Alignment="Center" LegendStyle="Table" Docking="right" IsEquallySpacedItems="True" LegendItemOrder="ReversedSeriesOrder" Font="{0}, 11px" ShadowColor="0, 0, 0, 0" ForeColor="59, 59, 59" />
</Legends>
</Chart>
</presentationdescription>
<isdefault>false</isdefault>
</visualization>

Stacked Bar Chart with aggregated total

 <visualization>
<visualizationid>{C618533F-3784-E211-8B16-78E3B5114607}</visualizationid>
<name>Aggregated Total on top of Stackedbar Chart</name>
<primaryentitytypecode>opportunity</primaryentitytypecode>
<datadescription>
<datadefinition>
<fetchcollection>
<fetch mapping="logical" aggregate="true">
<entity name="opportunity">
<attribute groupby="true" alias="purchase_process" name="purchaseprocess" />
<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>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="develop" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="2-Develop" />
</filter>
</link-entity>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="propose" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="3-Propose" />
</filter>
</link-entity>
<link-entity name="opportunity" from="opportunityid" to="opportunityid" link-type="outer">
<attribute alias="close" name="estimatedvalue" aggregate="sum" />
<filter>
<condition attribute="stepname" operator="eq" value="4-Close" />
</filter>
</link-entity>
<attribute alias="aggregated_total" name="estimatedvalue" aggregate="sum" />
</entity>
</fetch>
</fetchcollection>
<categorycollection>
<category alias="purchase_process">
<measurecollection>
<measure alias="qualify" />
</measurecollection>
<measurecollection>
<measure alias="develop" />
</measurecollection>
<measurecollection>
<measure alias="propose" />
</measurecollection>
<measurecollection>
<measure alias="close" />
</measurecollection>
<measurecollection>
<measure alias="aggregated_total" />
</measurecollection>
</category>
</categorycollection>
</datadefinition>
</datadescription>
<presentationdescription>
<Chart Palette="None" PaletteCustomColors="55,118,193; 197,56,52; 149,189,66; 117,82,160; 49,171,204; 255,136,35; 97,142,206; 209,98,96; 168,203,104; 142,116,178; 93,186,215; 255,155,83">
<Series>
<Series ChartType="Stackedbar" LegendText="1-Qualify" Color="LightSteelBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedbar" LegendText="2-Develop" Color="CornflowerBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedbar" LegendText="3-Propose" Color="RoyalBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Stackedbar" LegendText="4-Close" Color="DarkBlue" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"></Series>
<Series ChartType="Bar" IsVisibleInLegend="False" IsValueShownAsLabel="True" LabelFormat="$#,#,#" Color="Transparent" Font="{0}, 14px" LabelForeColor="59, 59, 59"></Series>
</Series>
<ChartAreas>
<ChartArea BorderColor="White" BorderDashStyle="Solid">
<AxisY LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorGrid LineColor="239, 242, 246" />
<MajorTickMark LineColor="165, 172, 181" />
<LabelStyle Font="{0}, 10.5px" Format="$#,#,k" ForeColor="59, 59, 59" />
</AxisY>
<AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount">
<MajorTickMark LineColor="165, 172, 181" />
<MajorGrid LineColor="Transparent" />
<LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" />
</AxisX>
</ChartArea>
</ChartAreas>
<Titles>
<Title Alignment="TopLeft" DockingOffset="-3" Font="{0}, 13px" ForeColor="59, 59, 59"></Title>
</Titles>
<Legends>
<Legend Alignment="Center" LegendStyle="Table" Docking="right" IsEquallySpacedItems="True" LegendItemOrder="ReversedSeriesOrder" Font="{0}, 11px" ShadowColor="0, 0, 0, 0" ForeColor="59, 59, 59" />
</Legends>
</Chart>
</presentationdescription>
<isdefault>false</isdefault>
</visualization>

, , , , , , ,

61 Comments