<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Arrange Act Assert &#187; SQL Server Reporting Services</title> <atom:link href="http://www.arrangeactassert.com/category/sql-server-reporting-services/feed/" rel="self" type="application/rss+xml" /><link>http://www.arrangeactassert.com</link> <description>Jag Reehal on Agile Development, ASP.NET MVC and all manner of good stuff</description> <lastBuildDate>Thu, 24 Nov 2011 00:01:20 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>How To Create Heat Maps In Sql Server Reporting Services</title><link>http://www.arrangeactassert.com/how-to-create-heat-maps-in-sql-server-reporting-services/</link> <comments>http://www.arrangeactassert.com/how-to-create-heat-maps-in-sql-server-reporting-services/#comments</comments> <pubDate>Mon, 08 Feb 2010 21:04:34 +0000</pubDate> <dc:creator>Jag Reehal</dc:creator> <category><![CDATA[SQL Server Reporting Services]]></category><guid
isPermaLink="false">http://www.arrangeactassert.com/?p=577</guid> <description><![CDATA[Recently I&#8217;ve been doing some work with Microsoft Sql Server Reporting Services. One of the tasks I was given was to create a report with a heat map, which means you transform a report that looks like this to something that looks like this As you can see the a heat map is excellent way [...]]]></description> <content:encoded><![CDATA[<p>Recently I&#8217;ve been doing some work with <a
href="http://www.microsoft.com/sqlserver/2008/en/us/reporting.aspx">Microsoft Sql Server Reporting Services</a>.  One of the tasks I was given was to create a report with a heat map, which means you transform a report that looks like this</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/PlainReport.PNG" alt="Plain Report" width=700 height=57 align=left /></p><p>to something that looks like this</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/BobsHeatmapReport.PNG" alt="Bobs Heat Map Report"  width=700 height=57 align=left  /></p><p>As you can see the a heat map is excellent way to visualize data.</p><p>This was done without the use of any plugins.  I implemented the heat map in Reporting Services by following <a
href="http://blogs.msdn.com/bobmeyers/">Bob Meyers</a> excellent solution in his &#8216;<a
href="http://blogs.msdn.com/bobmeyers/archive/2009/07/31/add-excel-like-color-scale-conditional-formatting-to-your-reports.aspx">Add Excel-like &#8220;color scale&#8221; conditional formatting to your reports</a>&#8216; blog post.</p><h3 class="subheading">Exporting to Excel</h3><p>One of the requirements for my work was for users to be able to export the report into Microsoft Excel.  Unfortunately it was at this point Bob&#8217;s solution didn&#8217;t work out for me.  The problem was I was getting cells with a black background color as shown below.</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/ErrorsExportingToExcel.PNG" alt="Errors Exporting To Excel" width=700 height=298 align=left /></p><p>So I came up with an alternative solution.</p><h3 class="subheading">An Alternative Sql Server Reporting Services Heat Map Generator</h3><p>So instead of using hex codes for the color like Bob does, I wanted to play it safe and use Microsoft colors i.e. those in the System.Drawing library.</p><p>The code below shows the GetHeatmapColor function which takes in three arguments and returns a string for the color</p><pre class="brush: vb; gutter: false; title: ; toolbar: true; notranslate">
Public Class SqlReportingServicesHeatMapGenerator
    Public Function GetHeatmapColor(ByVal textBoxValue, ByVal minDataSetValue, ByVal maxDataSetValue) As String
        Dim colours As String() = New String() {&quot;Green&quot;, &quot;LimeGreen&quot;, &quot;Yellow&quot;, &quot;Orange&quot;, &quot;OrangeRed&quot;, &quot;Red&quot;}

        If textBoxValue = 0 Then
            Return colours(0)
        End If

        If minDataSetValue = maxDataSetValue Then
            Return colours(0)
        End If

        If textBoxValue &gt; maxDataSetValue Then
            Return colours(colours.Length - 1)
        End If

        Dim divider As Integer = (maxDataSetValue - minDataSetValue + 1) / 5
        Dim index As Integer = textBoxValue / divider
        GetHeatmapColor = colours(index)

    End Function
End Class
</pre><p>This function can be unit tested like this.  Yes I know this falls a long way from 100% test coverage, but this is just an example <img
src='http://www.arrangeactassert.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><pre class="brush: vb; gutter: false; title: ; toolbar: true; notranslate">
Imports NUnit.Framework

&lt;TestFixture()&gt; _
Public Class When_Getting_The_Fill_Color
    Private _heatMapGenerator As New SqlReportingServicesHeatMapGenerator()
    &lt;Test()&gt; _
    Public Sub Should_Return_Green_For_Zero()
        Dim result = _heatMapGenerator.GetHeatmapColor(0, 1, 100)
        Assert.AreEqual(&quot;Green&quot;, result)
    End Sub

    &lt;Test()&gt; _
    Public Sub Should_Return_Green_For_Lowest_Value()
        Dim result = _heatMapGenerator.GetHeatmapColor(1, 1, 100)
        Assert.AreEqual(&quot;Green&quot;, result)
    End Sub

    &lt;Test()&gt; _
    Public Sub Should_Return_Red_For_Highest_Value()
        Dim result = _heatMapGenerator.GetHeatmapColor(100, 1, 100)
        Assert.AreEqual(&quot;Red&quot;, result)
    End Sub

    &lt;Test()&gt; _
    Public Sub Should_Return_Green_If_All_Values_Are_The_Same()
        Dim result = _heatMapGenerator.GetHeatmapColor(1, 1, 1)
        Assert.AreEqual(&quot;Green&quot;, result)
    End Sub

    &lt;Test()&gt; _
    Public Sub Should_Return_Red_Even_If_Cell_Value_Is_Greater_Than_The_Maximum()
        Dim result = _heatMapGenerator.GetHeatmapColor(1164, 1, 896)
        Assert.AreEqual(&quot;Red&quot;, result)
    End Sub
End Class
</pre><h3 class="subheading">Implementing The Solution</h3><p>The colors on the report are shown using the fill property of a text box and an expression to determine what the fill color should be.  Follow the steps below to create a heat map in Reporting Services using either Report Builder or Visual Studio.</p><p>First create a data source and dataset (we will not be connecting to any databases).  Right click on the dataset and select query</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/RightClickQuery.PNG" alt="Right click on the dataset and select query" align=left /></p><p>In the query for the dataset paste in the sql below</p><pre class="brush: sql; gutter: false; title: ; toolbar: true; notranslate">
DECLARE @LogTable TABLE (WebServer VARCHAR(10),[Hour] TINYINT, NumberOfUsers INT)
INSERT INTO @LogTable VALUES ('WebServer1',0,0)
INSERT INTO @LogTable VALUES ('WebServer1',1,2)
INSERT INTO @LogTable VALUES ('WebServer1',2,4)
INSERT INTO @LogTable VALUES ('WebServer1',3,6)
INSERT INTO @LogTable VALUES ('WebServer1',4,8)
INSERT INTO @LogTable VALUES ('WebServer1',5,10)
INSERT INTO @LogTable VALUES ('WebServer1',6,12)
INSERT INTO @LogTable VALUES ('WebServer1',7,14)
INSERT INTO @LogTable VALUES ('WebServer1',8,16)
INSERT INTO @LogTable VALUES ('WebServer1',9,18)
INSERT INTO @LogTable VALUES ('WebServer1',10,20)
INSERT INTO @LogTable VALUES ('WebServer1',11,22)
INSERT INTO @LogTable VALUES ('WebServer1',12,24)
INSERT INTO @LogTable VALUES ('WebServer1',13,22)
INSERT INTO @LogTable VALUES ('WebServer1',14,21)
INSERT INTO @LogTable VALUES ('WebServer1',15,20)
INSERT INTO @LogTable VALUES ('WebServer1',16,18)
INSERT INTO @LogTable VALUES ('WebServer1',17,16)
INSERT INTO @LogTable VALUES ('WebServer1',18,14)
INSERT INTO @LogTable VALUES ('WebServer1',19,12)
INSERT INTO @LogTable VALUES ('WebServer1',20,10)
INSERT INTO @LogTable VALUES ('WebServer1',21,8)
INSERT INTO @LogTable VALUES ('WebServer1',22,6)
INSERT INTO @LogTable VALUES ('WebServer1',23,4) 

SELECT WebServer, [Hour], NumberOfUsers FROM @LogTable
</pre><p>Next create a table, using hour as the column and the number of users as the data field</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/Report.PNG" alt="Creating the table" align=left /></p><p>Now in right click on the report designer and select the &#8220;Report Properties&#8221; option, and then the &#8220;Code&#8221; tab.  Copy the GetHeatmapColor function (NOT the SqlReportingServicesHeatMapGenerator class) and paste it into the window</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/EnteringCode.PNG" alt="Entering the VBA code into the report"  /></p><p>Right click in the text box that you want to generate the heat map for and select &#8220;Text Box Properties&#8221; (or use the properties window)</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/TextBoxProperties.PNG" alt="Text Box Properties"  /></p><p>Then choose the &#8220;Fill&#8221; tab and click the Expression button.</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/EnteringTheExpression.PNG" alt="Entering the Expression"  /></p><p>In the expression window enter the line below</p><pre class="brush: vb; gutter: false; title: ; toolbar: true; notranslate">
=Code.GetHeatmapColor(Sum(Fields!NumberOfUsers.Value), Min(Fields!NumberOfUsers.Value, &quot;DataSet1&quot;), Max(Fields!NumberOfUsers.Value, &quot;DataSet1&quot;))
</pre><p>As Bob says his post &#8220;The argument &#8216;Dataset1&#8242; defines the scope in which the min or max value is calculated, which must be a parent scope of the current scope.&#8221;</p><p>If you preview the report you should see the following</p><p><img
src="http://www.arrangeactassert.com/wp-content/themes/resources/images/JagsHeatmapReport.PNG" alt="Jags Heat Map Report" width=700 height=57 align=left /></p> ]]></content:encoded> <wfw:commentRss>http://www.arrangeactassert.com/how-to-create-heat-maps-in-sql-server-reporting-services/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> </channel> </rss>
<!-- Served from: www.arrangeactassert.com @ 2012-02-05 23:45:27 by W3 Total Cache -->
