{"id":509,"date":"2014-09-10T13:37:48","date_gmt":"2014-09-10T18:37:48","guid":{"rendered":"https:\/\/mkncreations.com\/site\/?p=509"},"modified":"2014-09-10T15:08:07","modified_gmt":"2014-09-10T20:08:07","slug":"display-total-on-top-of-stacked-chart","status":"publish","type":"post","link":"https:\/\/mkncreations.com\/site\/2014\/09\/display-total-on-top-of-stacked-chart\/","title":{"rendered":"Display Total on Top of Stacked Chart"},"content":{"rendered":"<p><strong>Source:<\/strong> <a title=\"http:\/\/www.sqljason.com\/2010\/06\/display-total-on-top-of-stacked-chart_8589.html\" href=\"http:\/\/www.sqljason.com\/2010\/06\/display-total-on-top-of-stacked-chart_8589.html\">http:\/\/www.sqljason.com\/2010\/06\/display-total-on-top-of-stacked-chart_8589.html<\/a><\/p>\n<p>It is a normal phenomenon that human beings take most of the simple things for granted. Take this case, one of my blog readers sent me a mail asking how to display the total on top of a stacked chart in SSRS. The first time I read it, I was almost going to blurt &#8211; just enable some property to display subtotals. But the more I thought about it, the more elusive the property became and that is when I realized there is no such property. So for the benefit of all, I thought about posting the workaround that I devised for this.<\/p>\n<p>Suppose I have a simple stacked column chart with Month on Categories, Product Category on Series and Sales as the measure. The requirement is to display the total of all Product Categories for a month on top of the stacked column chart. The required output is shown in the below image.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Stacked-Column-Chart-Total_thumb1.jpg\" \/><\/p>\n<p>For this, follow the steps below:-<\/p>\n<p>1) The original query was<\/p>\n<blockquote><p>SELECT Month,<br \/>\nCategory,<br \/>\nSales<br \/>\nFROM Sales<\/p><\/blockquote>\n<p>Modify it as follows<\/p>\n<blockquote><p>SELECT Month,<br \/>\nCategory,<br \/>\nSales<br \/>\nFROM Sales<br \/>\nUNION<br \/>\nSELECT Month,<br \/>\n&#8216;Total&#8217; AS Category,<br \/>\n0.1 * SUM(Sales) AS Sales<br \/>\nFROM Sales<br \/>\nGROUP BY Month;<\/p><\/blockquote>\n<p>This is done to include an extra row called Total for Product Categories. The value for Sales for this row would be 10% of the total Sales of that month.<\/p>\n<p>2) Go to the Design tab, right click on the chart and enable the Show Data Labels option. Then select the series label properties by right clicking on the data labels.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Show-Data-Labels_thumb1.jpg\" \/><\/p>\n<p>3) Edit the Label data and enter the following expression<\/p>\n<blockquote><p>=iif(Fields!Category.Value=&#8221;Total&#8221;,sum(Fields!Sales.Value,&#8221;Chart1_CategoryGroup&#8221;)-sum(Fields!Sales.Value),&#8221;&#8221;)<\/p><\/blockquote>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Label-Data-Expression_thumb1.jpg\" \/><\/p>\n<p>The above expression displays blank if the Product Category is not \u201cTotal\u201d and displays the sum of the entire Product Categories for that month (including the value for Total) \u2013 sum of the Total field.<\/p>\n<p>P.S. : \u201cChart1_CategoryGroup\u201d would have to be replaced with the category group name of your stacked column chart. To find this, click on the Month (category) button in the chart and press F4. You will find the Name of the group in the property panel that opens up as shown below.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Find-category-group-name_thumb1.jpg\" \/><\/p>\n<p>4) Now we should be getting the following output when we click on the Preview tab.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Statcked-column-chart-with-Total_thumb1.jpg\" \/><\/p>\n<p>Go back to the Design tab and click on Product Category (series) in the chart and press F4 to open the property panel. Enter the below expression in the Label property<\/p>\n<blockquote><p>=iif(Fields!Category.Value=&#8221;Total&#8221;,&#8221; &#8220;,Fields!Category.Value)<\/p><\/blockquote>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Edit-Label-expression-for-series_thumb1.jpg\" \/><\/p>\n<p>This is done so that the Total value will not appear in the legend.<\/p>\n<p>5) Right click on the stacked columns and select series properties.<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Series-properties_thumb1.jpg\" \/><\/p>\n<p>6) Go to the Fill tab and enter the following expression for the color<\/p>\n<blockquote><p>=iif(Fields!Category.Value=&#8221;Total&#8221;,&#8221;Transparent&#8221;,&#8221;Automatic&#8221;)<\/p><\/blockquote>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Color-expression_thumb1.jpg\" \/><\/p>\n<p>This is done so that the Total value will be transparent and hence, would look like it is not present.<\/p>\n<p>7) Preview the report and you should be getting the required output<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Final-result_thumb1.jpg\" \/><\/p>\n<p>This report has been done with SSRS 2008 R2 but the concept should work in SSRS 2008 more or less the same way.<\/p>\n<p><strong>Update<\/strong><\/p>\n<p>For SSRS 2008 users, it has been noticed that all the bars become black when the above fill expression is used. That is because the Automatic colour can not be used in expressions. So as a workaround, follow the step below instead of the 6th step above<\/p>\n<p>1) In BIDS, press Alt+R to open the Report Tab and select Report Properties. Then go to the code section and paste the following code<\/p>\n<blockquote><p>Private colorPalette As String() = {&#8220;Green&#8221;, &#8220;Blue&#8221;, &#8220;Red&#8221;, &#8220;Orange&#8221;, &#8220;Aqua&#8221;, &#8220;Teal&#8221;, &#8220;Gold&#8221;, &#8220;RoyalBlue&#8221;, &#8220;#A59D93&#8221;, &#8220;#B8341B&#8221;, &#8220;#352F26&#8221;, &#8220;#F1E7D6&#8221;, &#8220;#E16C56&#8221;, &#8220;#CFBA9B&#8221;}<br \/>\nPrivate count As Integer = 0<br \/>\nPrivate mapping As New System.Collections.Hashtable()<br \/>\nPublic Function GetColor(ByVal groupingValue As String) As String<br \/>\nIf mapping.ContainsKey(groupingValue) Then<br \/>\nReturn mapping(groupingValue)<br \/>\nEnd If<br \/>\nDim c As String = colorPalette(count Mod colorPalette.Length)<br \/>\ncount = count + 1<br \/>\nmapping.Add(groupingValue, c)<br \/>\nReturn c<br \/>\nEnd Function<\/p><\/blockquote>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/mkncreations.com\/site\/wp-content\/uploads\/Rep-properties_thumb1.jpg\" \/><\/p>\n<p>Right now, there are only 14 colours in the palette but more colours can be added if you have more than 14 values in the series.<\/p>\n<p>2) Use the following expression for colour in the fill tab of series properties.<\/p>\n<blockquote><p>=iif(Fields!Category.Value=&#8221;Total&#8221;, &#8220;Transparent&#8221;,Code.GetColor(Fields!Category.Value))<\/p><\/blockquote>\n<p>This would do the trick.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: http:\/\/www.sqljason.com\/2010\/06\/display-total-on-top-of-stacked-chart_8589.html It is a normal phenomenon that human beings take most of the simple things for granted. Take this case, one of my blog&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,11],"tags":[129,131,61,95,79,21,50,78,38,130,42,49],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-how_to","category-ssrs","tag-129","tag-chart","tag-column","tag-display","tag-microsoft","tag-ms","tag-sql-2","tag-sql2008","tag-ssrs-2","tag-stacked","tag-top","tag-tsql"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/posts\/509"}],"collection":[{"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":4,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":521,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/posts\/509\/revisions\/521"}],"wp:attachment":[{"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mkncreations.com\/site\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}