<?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>A Developer&#039;s Blog &#187; Reporting Services 2008 R2</title>
	<atom:link href="http://blog.hoegaerden.be/tag/reporting-services-2008-r2/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hoegaerden.be</link>
	<description>SQL Server, BI, .NET, IT and anything else I have been playing with.</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:15:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Changing Parameter Order In An SSRS Report</title>
		<link>http://blog.hoegaerden.be/2011/04/29/changing-parameter-order-in-an-ssrs-report/</link>
		<comments>http://blog.hoegaerden.be/2011/04/29/changing-parameter-order-in-an-ssrs-report/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 16:06:44 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[Reporting Services 2008 R2]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/04/29/changing-parameter-order-in-an-ssrs-report/</guid>
		<description><![CDATA[This week I was asked twice, by two different (luckily) colleagues, if I knew how to change the order of the parameters in a report in SQL Server Reporting Services.  I still remember that the first time when I needed this after my upgrade to 2008, I also spent some time looking for it.  Apparently [...]]]></description>
			<content:encoded><![CDATA[<p>This week I was asked twice, by two different (luckily) colleagues, if I knew how to change the order of the parameters in a report in SQL Server Reporting Services.  I still remember that the first time when I needed this after my upgrade to 2008, I also spent some time looking for it.  Apparently it’s still hard to find so I’ve now decided to write a quick post about it.  I promise you, once you know it you’ll say “how silly”.</p>
<p>The following screenshot should say it all:</p>
<p><img style="display: inline; border: 0px;" title="Use the arrows in the Report Data pane to move parameters up or down" src="http://blog.hoegaerden.be/wp-content/uploads/image406.png" border="0" alt="Use the arrows in the Report Data pane to move parameters up or down" width="177" height="250" /></p>
<p>That’s right, those two small arrow buttons in the Report Data pane can be used to move the parameters up or down.  They may be difficult to spot but once you’ve found them you’ll never forget.  Why are they difficult to spot?</p>
<p><img style="display: inline; border: 0px;" title="Move Up/Down buttons greyed out" src="http://blog.hoegaerden.be/wp-content/uploads/image407.png" border="0" alt="Move Up/Down buttons greyed out" width="170" height="45" /></p>
<p>For several reasons:</p>
<ul>
<li>they are greyed out when no parameter is selected</li>
<li>they may not be visible when your Report Data pane is too small</li>
</ul>
<p>How silly huh?</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="How to: Change the Order of a Report Parameter (Reporting Services)" href="http://msdn.microsoft.com/en-us/library/cc281392.aspx" target="_blank">How to: Change the Order of a Report Parameter (Reporting Services)</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F04%2F29%2Fchanging-parameter-order-in-an-ssrs-report%2F&amp;title=Changing%20Parameter%20Order%20In%20An%20SSRS%20Report" id="wpa2a_2"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/04/29/changing-parameter-order-in-an-ssrs-report/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Where The Sheets Have A Name</title>
		<link>http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/</link>
		<comments>http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 18:38:50 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[Reporting Services 2008 R2]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/</guid>
		<description><![CDATA[Did you know that as of SQL Server Reporting Services 2008 R2 you can give the worksheets a customized name when exporting your report to Excel?  If you didn’t, or you did but never took the time to find out how you’d implement that, I’ll show you here and now! For this example I’ll be [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that as of <strong>SQL Server Reporting Services 2008 R2</strong> you can give the worksheets a customized name when exporting your report to Excel?  If you didn’t, or you did but never took the time to find out how you’d implement that, I’ll show you here and now!</p>
<p>For this example I’ll be starting off from the report created in <a title="Cascading Calculated Fields (SSRS)" href="http://blog.hoegaerden.be/2011/03/07/cascading-calculated-fields-ssrs/">my earlier post on Cascading Calculated Fields</a>.</p>
<p>The result can be <a title="NamingExcelSheets.rdl" href="http://cid-81c8b064cbbe1698.office.live.com/self.aspx/.Public/blog/NamingExcelSheets.rdl" target="_blank">downloaded from my Skydrive through this link</a>.</p>
<h2>The Scenario</h2>
<p>As you may recall, our report shows a list of all our company’s products.  When the report gets exported to Excel, each product category should get its own sheet.  So all products from the Audio category should be located in a sheet called “Audio”, all Games and Toys in a sheet called “Games and Toys”, and so on.</p>
<h2>The Report</h2>
<h3>Starting Position</h3>
<p>Let’s first have a quick look what the export to Excel currently looks like, without any modifications to the report.</p>
<p><img style="display: inline; border-width: 0px;" title="Default export to Excel - all data in one sheet" src="http://blog.hoegaerden.be/wp-content/uploads/image379.png" border="0" alt="Default export to Excel - all data in one sheet" width="700" height="639" /></p>
<p>All records are being exported to just one sheet.  And, by default, the name of the sheet is the name of the report.  (I made a copy of my existing report and called it NamingExcelSheets.rdl.)</p>
<p>In case you want to change the default name of the sheet, it’s possible.  On the report itself, there’s a property called <strong>InitialPageName</strong>.</p>
<p><img style="display: inline; border-width: 0px;" title="Use the InitialPageName property on the report to change the default name of the Excel sheet" src="http://blog.hoegaerden.be/wp-content/uploads/image380.png" border="0" alt="Use the InitialPageName property on the report to change the default name of the Excel sheet" width="428" height="437" /></p>
<p>Fill in a value and here’s the result in Excel:</p>
<p><img style="display: inline; border-width: 0px;" title="The Excel sheet with its default name changed to a very unique name" src="http://blog.hoegaerden.be/wp-content/uploads/image381.png" border="0" alt="The Excel sheet with its default name changed to a very unique name" width="667" height="457" /></p>
<h3>Adding The Category Group</h3>
<p>To be able to get the different categories into different sheets, we need to add a group on Category to the tablix in the report.</p>
<p>With the tablix selected, right-click the <em>Details </em>line in the <em>Row Groups </em>pane and select <strong>Add Group &gt; Parent Group</strong>.  Select ProductCategoryName as field to group by and activate the <strong>Add group header</strong> checkbox.</p>
<p><img style="display: inline; border-width: 0px;" title="Add group on Product Category" src="http://blog.hoegaerden.be/wp-content/uploads/image382.png" border="0" alt="Add group on Product Category" width="682" height="320" /></p>
<p>Remove the group column that gets added automatically and move the header cells from the main header to the group header.  Delete the main header row so that you end up with something like this:</p>
<p><img style="display: inline; border-width: 0px;" title="Tablix with group on Product Category added" src="http://blog.hoegaerden.be/wp-content/uploads/image383.png" border="0" alt="Tablix with group on Product Category added" width="580" height="93" /></p>
<p>Open up the <strong>Group Properties </strong>by double-clicking the new ProductCategoryName item in the <em>Row Groups </em>pane.  Select the <em>Page Breaks </em>page and activate the <strong>Between each instance of a group </strong>checkbox.  Doing this ensures that each group gets its own page in the report, and its own sheet in Excel.</p>
<p><img style="display: inline; border-width: 0px;" title="Adding page breaks between the instances of a group" src="http://blog.hoegaerden.be/wp-content/uploads/image384.png" border="0" alt="Adding page breaks between the instances of a group" width="585" height="482" /></p>
<p>Let’s render the report and export to Excel to have a look at the effect of adding these page breaks.</p>
<p><img style="display: inline; border-width: 0px;" title="Report exported to Excel with each group in a separate sheet" src="http://blog.hoegaerden.be/wp-content/uploads/image385.png" border="0" alt="Report exported to Excel with each group in a separate sheet" width="661" height="398" /></p>
<p>Indeed, every group has gotten its own worksheet.  However, they’ve also gotten the very original names such as Sheet1, Sheet2 and so on.</p>
<h3>Customizing The Names Of The Sheets</h3>
<p>On to the final part of the requirements: giving our own customized name to the generated Excel sheets.  This is actually really easy once you know how to do this.</p>
<p>First select the ProductCategoryName group in the Row Groups pane so that its properties are displayed in the Properties pane.  In the Properties pane, locate the Group &gt; PageName property and specify the following expression:</p>
<pre class="code">=Fields!ProductCategoryName.Value</pre>
<p>That’s it, that’s all you need to do!  Don’t believe me?  Here’s what the export to Excel now looks like:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image386.png"><img style="display: inline; border-width: 0px;" title="Data exported to Excel, with customized sheetnames" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb89.png" border="0" alt="Data exported to Excel, with customized sheetnames" width="700" height="347" /></a></p>
<h2>Conclusion</h2>
<p>As we’ve seen in this article, it really doesn’t take too much effort to implement a custom name for the worksheets when exporting a report to Excel.  Neat feature!</p>
<p>Have fun!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="Understanding Pagination in Reporting Services (Report Builder 3.0 and SSRS)" href="http://msdn.microsoft.com/en-us/library/dd255278.aspx" target="_blank">Understanding Pagination in Reporting Services (Report Builder 3.0 and SSRS)</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2011%2F03%2F23%2Fwhere-the-sheets-have-a-name-ssrs-excel-export%2F&amp;title=Where%20The%20Sheets%20Have%20A%20Name" id="wpa2a_4"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Implementing Data Bars In A Grouped Table</title>
		<link>http://blog.hoegaerden.be/2010/05/27/implementing-data-bars-in-a-grouped-table/</link>
		<comments>http://blog.hoegaerden.be/2010/05/27/implementing-data-bars-in-a-grouped-table/#comments</comments>
		<pubDate>Thu, 27 May 2010 20:16:21 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Reporting Services 2008 R2]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/05/27/implementing-data-bars-in-a-grouped-table/</guid>
		<description><![CDATA[Earlier I wrote an article about the new lookup functions that ship with SQL Server 2008 R2.&#160; Today I’m going to show you another new feature of SSRS 2008 R2, this time in the visualization department.&#160; This feature is the Data Bar.&#160; With this new component it’s fairly easy to make your tabular data a [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier I wrote an article about <a title="Looking Up Data On Different Sources" href="http://blog.hoegaerden.be/2010/05/16/looking-up-data-on-different-sources/">the new lookup functions</a> that ship with SQL Server 2008 R2.&#160; Today I’m going to show you another new feature of SSRS 2008 R2, this time in the visualization department.&#160; This feature is the <a title="BOL 2008R2: Sparklines and Data Bars" href="http://msdn.microsoft.com/en-us/library/ee636365%28v=SQL.105%29.aspx" target="_blank">Data Bar</a>.&#160; With this new component it’s fairly easy to make your tabular data a lot more visual, and thus easier to interpret.&#160; And here’s how to do it.</p>
<p>I’ll be starting from the report that I created in <a title="Your First OLAP Report" href="http://blog.hoegaerden.be/2010/01/24/your-first-olap-report/">Your First OLAP Report</a>.&#160; That allows me to focus on the visualization part, without first needing to build a table report.&#160; (Okay, I admit, it’s not 100% the same report – I’ve modified the colors a bit because I felt the green was too dark.) But obviously this method will work with any report that’s showing data in a table.</p>
<p>Furthermore I’m running SQL Server 2008 R2 Nov CTP, 64-bit, and I’m using the BIDS to develop the report.</p>
<p>The final result <a title="Download: &quot;First OLAP Report With Data Bars&quot;" href="http://cid-81c8b064cbbe1698.skydrive.live.com/self.aspx/.Public/blog/FirstOLAPReportWithDataBars.rdl" target="_blank">can be downloaded from Skydrive here</a>.</p>
<h2>Implementing The Data Bar</h2>
<p>The report that we’re using is showing some sales figures grouped in three levels: Country, State/Province and City.&#160; We’re going to add an extra column on the right of the table to contain the data bar.&#160; Let’s first explore the Toolbox pane to discover the new visualization report items.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The new Reporting Services 2008 R2 report items: Map, Data Bar, Sparkline and Indicator" border="0" alt="The new Reporting Services 2008 R2 report items: Map, Data Bar, Sparkline and Indicator" src="http://blog.hoegaerden.be/wp-content/uploads/image262.png" width="120" height="342" /></p>
<p>The new items have been highlighted in yellow.&#160; As you can see, besides <strong>Data Bar </strong>there’s also <strong>Sparkline, </strong><strong>Map </strong>and <strong>Indicator</strong>.&#160; But those are not on topic now.</p>
<p>To add a Data Bar, simply drag it from the Toolbox into a textbox on the report.&#160; Doing that will show the following popup window:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Select Data Bar Type window" border="0" alt="Select Data Bar Type window" src="http://blog.hoegaerden.be/wp-content/uploads/image263.png" width="348" height="482" /></p>
<p>From left to right, there’s Bar, Stacked Bar and 100% Stacked Bar.&#160; And those are also available in vertical direction, Column.&#160; I’m going to use the regular Bar as highlighted in the screenshot.</p>
<p>The Data Bar has now been added to the report, but it doesn’t do anything yet.&#160; We first need to tell it what data to visualize.&#160; Clicking it once will select it, clicking it once more will show us the following <strong>Chart Data </strong>popup:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Data Bar: Chart Data" border="0" alt="Data Bar: Chart Data" src="http://blog.hoegaerden.be/wp-content/uploads/image264.png" width="612" height="434" /></p>
<p>Click the plus icon to get a drop-down of fields in the dataset.&#160; Select the numeric field that you want to visualize, in my case that’s the Reseller_Sales_Amount.</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image350.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Data Bar: Chart Data with Reseller_Sales_Amount selected" border="0" alt="Data Bar: Chart Data with Reseller_Sales_Amount selected" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb81.png" width="700" height="385" /></a>&#160;</p>
<p>By default, the aggregation used on the data is Sum.&#160; But there are other options as well, have a look at the dropdown next to the [Sum(Reseller_Sales…&#160; In the example here I’m going to keep the Sum.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Other aggregation functions of the Data Bar" border="0" alt="Other aggregation functions of the Data Bar" src="http://blog.hoegaerden.be/wp-content/uploads/image266.png" width="437" height="450" /></p>
<p>The report Preview looks like this:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image267.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Report preview with the data bar" border="0" alt="Report preview with the data bar" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb63.png" width="700" height="208" /></a></p>
<p>In this report we can easily see what states have got a higher sales amount: those with the longer bars.</p>
<p>Let’s add bars for the Country level as well.&#160; There are two ways to achieve that: you can either drag a new Data Bar onto the report or you can just copy/paste the textbox containing our first Data Bar.</p>
<p>To make the report easier to read I will change the color of the Data Bar to the color of the group’s background.&#160; Setting up the color of the Data Bar is done as follows: select the Data Bar so that you get the Chart Data popup.&#160; In the Properties pane you should see that the Chart Series is selected.&#160; Then right-click on the bar and select <strong>Series Properties</strong>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The right-click menu on the Data Bar." border="0" alt="The right-click menu on the Data Bar." src="http://blog.hoegaerden.be/wp-content/uploads/image268.png" width="434" height="445" /></p>
<p>In the <strong>Series Properties</strong> window, select the <strong>Fill</strong> page and select your favorite color.&#160; If you want you can also use a gradient fill or pattern.&#160; You can even use a Switch statement and color them differently depending on their value, similar to the method that I used in my <a title="SSRS and MDX: Detecting Missing Fields" href="http://blog.hoegaerden.be/2009/07/06/ssrs-and-mdx-detecting-missing-fields/">SSRS and MDX: Detecting Missing Fields</a> article.&#160; Well, in short, any expression that you can think of and results in a color will work fine!</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Series Properies: setting up the Fill color" border="0" alt="Series Properies: setting up the Fill color" src="http://blog.hoegaerden.be/wp-content/uploads/image269.png" width="585" height="520" /></p>
<p>With the second data bar and custom coloring set up, here’s the rendered report:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image270.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Report with data bar on two grouping levels" border="0" alt="Report with data bar on two grouping levels" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb64.png" width="700" height="237" /></a></p>
<p>Hang on, is that correct? As you can see, the data bar for California is longer than the one for Canada while the sales amount for Canada is definitely the higher one.&#160; An even nicer example is United Kingdom with only one state England.&#160; Both amounts are equal yet their data bars are certainly not.</p>
<p>Well, this is because the data bar by default uses the same scope as the group where it’s put.&#160; Canada and United Kingdom are in the Country group and all Country data bars compare nicely to each other.&#160; California and England are in the State/Province group and also compare nicely to each other!</p>
<p>Depending on the report’s requirements this may or may not be the desired effect.&#160; But I wouldn’t be mentioning this if there weren’t any other options, would I?</p>
<h3>Setting The Maximum Value Of The Horizontal Axis</h3>
<p>A correct column label for our current column would be <em>“% of group</em>”.&#160; Let’s add a second column which will show the percentage of the row compared to the total of the dataset, “<em>% of overall total</em>”.&#160; After adding the extra column, copy/paste the data bars from the first column over into the new textboxes in the second column.</p>
<p>To get what we want, we need to tell the data bar that the maximum for the horizontal axis is the total of the dataset and not the total of the grouping level of the table.&#160; So, right-click one of the data bars in the new column and select <strong>Horizontal Axis Properties</strong>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Right-click menu on tablix textbox with a data bar" border="0" alt="Right-click menu on tablix textbox with a data bar" src="http://blog.hoegaerden.be/wp-content/uploads/image271.png" width="545" height="568" /></p>
<p>As you can see, the default for the <em>Maximum</em> value is set to “<em>Auto</em>”.&#160; Note that the name of my tablix is “Tablix1”, as shown in the <em>Align axes in</em> dropdown.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Horizontal Axis Properties" border="0" alt="Horizontal Axis Properties" src="http://blog.hoegaerden.be/wp-content/uploads/image272.png" width="585" height="530" /></p>
<p>Let’s replace the <em>Auto</em> as <strong>Maximum</strong> with the following expression:</p>
<pre class="code">=Sum(Fields!Reseller_Sales_Amount.Value, <span style="color: #a31515">&quot;Tablix1&quot;</span>)</pre>
<p>This expression says that we need the sum of the Reseller_Sales_Amount, scoped over the whole tablix.</p>
<p>Having changed the <strong>Maximum</strong> value on both data bars gives us the following preview:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image273.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Report rendered with status bar scoped over whole dataset" border="0" alt="Report rendered with status bar scoped over whole dataset" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb65.png" width="700" height="203" /></a></p>
<p>As you can see, this time around the data bars for England and United Kingdom have gotten the same size.&#160; Bars from different grouping levels can now be compared with each other.</p>
<h3>Showing Labels On The Data Bars</h3>
<p>In this report it would be interesting to add a label that displays the percentage to the status bars, so let’s do that.</p>
<p>For the percentage calculation of the first column of data bars we need to get the total of the current group and divide that by the total of the group one level higher.&#160; For the State/Province level that gives us the following expression:</p>
<pre class="code">=Sum(Fields!Reseller_Sales_Amount.Value)
    / Sum(Fields!Reseller_Sales_Amount.Value, <span style="color: #a31515">&quot;grpCountry&quot;</span>)</pre>
<p>The grpCountry refers to the name of the grouping one level higher, as shown in following screenshot:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The groupings as defined on my example tablix" border="0" alt="The groupings as defined on my example tablix" src="http://blog.hoegaerden.be/wp-content/uploads/image274.png" width="680" height="103" /></p>
<p>And for the Country level we need this expression:</p>
<pre class="code">=Sum(Fields!Reseller_Sales_Amount.Value)
    / Sum(Fields!Reseller_Sales_Amount.Value, <span style="color: #a31515">&quot;Tablix1&quot;</span>)</pre>
<p>The only difference with the previous expression is the scope.</p>
<p>“Ok, so where do I type those expressions?” I hear you think.&#160; Right-click the Data Bar (after first selecting the textbox that contains it) and choose <strong>Show Data Labels</strong>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Show Data Labels in right-click popup on Chart Series" border="0" alt="Show Data Labels in right-click popup on Chart Series" src="http://blog.hoegaerden.be/wp-content/uploads/image275.png" width="309" height="300" /></p>
<p>That adds a label to the chart but we still need to configure it to show the percentage.&#160; By default it uses the value as label.&#160; This can be verified in the <strong>Chart Series </strong>properties:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Series properties: UseValueAsLabel" border="0" alt="Chart Series properties: UseValueAsLabel" src="http://blog.hoegaerden.be/wp-content/uploads/image276.png" width="287" height="392" /></p>
<p>The <strong>UseValueAsLabel</strong> is set to <em>True</em>, confirming what I just stated.&#160; Furthermore, activating the <strong>Show Data Labels </strong>option also set the <strong>Visible</strong> property to <em>True</em>.&#160; So another way of adding the label is by just setting this property to <em>True</em>.</p>
<p>Let’s now configure that label.&#160; Right-click it and select <strong>Series Label Properties</strong>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Right-click menu on label" border="0" alt="Right-click menu on label" src="http://blog.hoegaerden.be/wp-content/uploads/image277.png" width="275" height="179" /></p>
<p>The General page of the <strong>Series Label Properties </strong>window allows you to define the Label data.&#160; That’s where you need to enter the expression that I mentioned earlier.</p>
<p>After you’ve entered the expression, the BIDS will ask you if you want to set the UseValueAsLabel to False, so click Yes.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Do you want to set the UseValueAsLabel to False?" border="0" alt="Do you want to set the UseValueAsLabel to False?" src="http://blog.hoegaerden.be/wp-content/uploads/image278.png" width="593" height="540" /></p>
<p>With the label selected as shown in the next screenshot you can use the formatting toolbar buttons to give it a decent font and all.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Data Bar with Label selected" border="0" alt="Data Bar with Label selected" src="http://blog.hoegaerden.be/wp-content/uploads/image279.png" width="207" height="37" /></p>
<p>For our second column of data bars the expressions need to take into account that we need the percentage as compared to all the data, unrelated to the level.&#160; This actually makes it easier because we can use the same expression on both the State/Province and Country level.&#160; Furthermore, it’s exactly the same expression as the one used on Country level in the first data bar column (i. e. the second expression above) because Country is the highest level.</p>
<p>Let’s have a look at the result in preview:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image280.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Preview of report with labels on data bars" border="0" alt="Preview of report with labels on data bars" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb66.png" width="700" height="185" /></a></p>
<p>Woah, looks like we forgot something doesn’t it?&#160; We forgot to format the label as being a percentage!&#160; There are two ways to get that done: through the <strong>Number</strong> page on the <strong>Series Label Properties </strong>window:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Series Label Properties: formatting number as percentage" border="0" alt="Series Label Properties: formatting number as percentage" src="http://blog.hoegaerden.be/wp-content/uploads/image281.png" width="585" height="482" /></p>
<p>Or by using the properties with the label selected (the Properties pane should show <strong>Chart Series Labels </strong>in the dropdown on top):</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Chart Series Labels properties" border="0" alt="Chart Series Labels properties" src="http://blog.hoegaerden.be/wp-content/uploads/image282.png" width="297" height="528" /></p>
<p>I’ve opted for a percentage without any decimals.</p>
<p>Let’s have another look at that report:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image283.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="The final report with two data bar columns" border="0" alt="The final report with two data bar columns" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb67.png" width="700" height="201" /></a></p>
<p>That sure looks better doesn’t it?&#160; The status bars on the right compare over the grouping levels while those on the left compare with each other within the same group.&#160; And they all have a clear label indicating what they represent.</p>
<p>And then colleague-expert <a title="mark_wills @ EE" href="http://www.experts-exchange.com/M_4390378.html" target="_blank">Mark Wills</a> jumps in with the following remark (rephrased a little):</p>
<blockquote>
<p>Hang on, are you really sure those bars on the left are what they should be?&#160; How&#8217;s it possible then that 71% of NSW (Australia) appears to be only about 20% and the 100% of England (United Kingdom) is only halfway filled?</p>
</blockquote>
<p>Interesting observation and indeed, Mark is right: those data bars on the left are still not right!&#160; Let’s get this fixed.</p>
<p>On the Country level the fix is really easy.&#160; What we want the bar to reflect here is the same as in the bar on the right: the percentage of the country compared to the whole dataset.&#160; That’s achieved using this expression as <em>Maximum</em> in the <strong>Horizontal Axis Properties</strong>:</p>
<pre class="code">=Sum(Fields!Reseller_Sales_Amount.Value, <span style="color: #a31515">&quot;Tablix1&quot;</span>)</pre>
<p>Here’s what that looks like:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Data bar on Country level now reflects the percentage of the group" border="0" alt="Data bar on Country level now reflects the percentage of the group" src="http://blog.hoegaerden.be/wp-content/uploads/image446.png" width="700" height="110" /></p>
<p>And finally, here’s the expression to be used to fix the data bar on State/Province level:</p>
<pre class="code">=Sum(Fields!Reseller_Sales_Amount.Value, <span style="color: #a31515">&quot;grpCountry&quot;</span>)</pre>
<p>Indeed, the data bar on this level should show the percentage compared to all the items in the group.</p>
<p>Final result:</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="All data bars fully operational as advertised!" border="0" alt="All data bars fully operational as advertised!" src="http://blog.hoegaerden.be/wp-content/uploads/image447.png" width="700" height="200" /></p>
<p><strong>Conclusion:</strong> it’s not a good idea to leave the Maximum setting in the Horizontal Axis Properties set to “Auto”.</p>
<p>Have fun putting those data bars on your reports!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="BOL 2008R2: What&#39;s New (Reporting Services)" href="http://msdn.microsoft.com/en-us/library/ms170438%28v=SQL.105%29.aspx" target="_blank">BOL 2008R2: What&#8217;s New (Reporting Services)</a></p>
<p><a title="BOL 2008R2: Sparklines and Data Bars" href="http://msdn.microsoft.com/en-us/library/ee636365%28v=SQL.105%29.aspx" target="_blank">BOL 2008R2: Sparklines and Data Bars</a></p>
<p><a title="An Introduction to Data Bars in SQL Server Reporting Services 2008 R2" href="http://blogs.msdn.com/seanboon/archive/2009/11/23/an-introduction-to-data-bars-in-sql-server-reporting-services-2008-r2.aspx" target="_blank">An Introduction to Data Bars in SQL Server Reporting Services 2008 R2</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2010%2F05%2F27%2Fimplementing-data-bars-in-a-grouped-table%2F&amp;title=Implementing%20Data%20Bars%20In%20A%20Grouped%20Table" id="wpa2a_6"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/05/27/implementing-data-bars-in-a-grouped-table/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Looking Up Data On Different Sources</title>
		<link>http://blog.hoegaerden.be/2010/05/16/looking-up-data-on-different-sources/</link>
		<comments>http://blog.hoegaerden.be/2010/05/16/looking-up-data-on-different-sources/#comments</comments>
		<pubDate>Sun, 16 May 2010 12:41:27 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SQLServerPedia Syndication]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Reporting Services 2008 R2]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2010/05/16/looking-up-data-on-different-sources/</guid>
		<description><![CDATA[Almost a year ago I wrote a small blog post to ask everyone to vote on a certain Connect item related to the linking of two datasets in a Reporting Services report.&#160; At this moment there have been 87 positive votes on the request. Now that SQL Server 2008 R2 has been RTM’ed, it’s time [...]]]></description>
			<content:encoded><![CDATA[<p>Almost a year ago I wrote <a title="Want to link datasets? Please vote!" href="http://blog.hoegaerden.be/2009/06/13/want-to-link-datasets-please-vote/">a small blog post</a> to ask everyone to vote on <a title="Merging / Linking datasets on report level (SSRS 2008)" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=419819" target="_blank">a certain Connect item</a> related to the linking of two datasets in a Reporting Services report.&#160; At this moment there have been 87 positive votes on the request.</p>
<p>Now that <a title="Microsoft SQL Server 2008 R2" href="http://www.microsoft.com/sqlserver/2008/en/us/r2.aspx" target="_blank">SQL Server 2008 R2</a> has been RTM’ed, it’s time to demonstrate new functionality in SSRS that allows the retrieval of data from another dataset, a dataset not linked to your data region.&#160; It’s not completely the same as actually joining two datasets, but it’s better than nothing – and it works!</p>
<p>In this article I’ll show you how exactly this works by using the new Lookup, LookupSet and MultiLookup SSRS functions.</p>
<p>I’m using the AdventureWorks 2008R2 relational database and the AdventureWorksDW 2008R2 data warehouse, <a title="AdventureWorks 2008R2 November CTP" href="http://msftdbprodsamples.codeplex.com/releases/view/24854" target="_blank">available from CodePlex</a>.&#160; The main data is coming from the data warehouse while all the lookups are done on the relational database.</p>
<h2>Setting Up A Basic Table Report</h2>
<p>In my report I’ve created a dataset called dsInternetSales.&#160; This dataset is retrieving data from the AdventureWorksDW2008R2 data warehouse using the following query:</p>
<pre class="code"><span style="color: blue">select </span>PROD<span style="color: gray">.</span>EnglishProductName<span style="color: gray">, </span>PROD<span style="color: gray">.</span>ProductAlternateKey<span style="color: gray">, </span>PROD<span style="color: gray">.</span>ListPrice<span style="color: gray">,
    </span>PSC<span style="color: gray">.</span>EnglishProductSubcategoryName<span style="color: gray">, </span>PC<span style="color: gray">.</span>EnglishProductCategoryName<span style="color: gray">,
    </span>S<span style="color: gray">.</span>OrderQuantity<span style="color: gray">, </span>S<span style="color: gray">.</span>SalesAmount
<span style="color: blue">from </span>FactInternetSales S
<span style="color: gray">inner join </span>DimProduct PROD <span style="color: blue">on </span>S<span style="color: gray">.</span>ProductKey <span style="color: gray">= </span>PROD<span style="color: gray">.</span>ProductKey
<span style="color: gray">inner join </span>DimProductSubcategory PSC
    <span style="color: blue">on </span>PROD<span style="color: gray">.</span>ProductSubcategoryKey <span style="color: gray">= </span>PSC<span style="color: gray">.</span>ProductSubcategoryKey
<span style="color: gray">inner join </span>DimProductCategory PC <span style="color: blue">on </span>PSC<span style="color: gray">.</span>ProductCategoryKey <span style="color: gray">= </span>PC<span style="color: gray">.</span>ProductCategoryKey</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>Using that dataset, I’ve set up a Table as shown in following screenshot.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Basic Table Report" border="0" alt="Basic Table Report" src="http://blog.hoegaerden.be/wp-content/uploads/image249.png" width="630" height="294" /> </p>
<p>The Details group has been set up to group on ProductAlternateKey.&#160; On top of the Details group, I’ve grouped on EnglishProductSubcategoryName and the top-level group is grouping on EnglishProductCategoryName.&#160; The Order Quantity column is displaying the sum of the OrderQuantity values for each ProductAlternateKey.</p>
<p>The result is a report that shows all (internet) sales per product, without any filtering.&#160; Very useful report if you want to know how many items your company has sold since it’s existence.&#160; Okay, management would probably like to see some filtering on here, but that’s not the purpose of this article.</p>
<p>Here’s what it looks like in Preview:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Basic Table Report Rendered" border="0" alt="Basic Table Report Rendered" src="http://blog.hoegaerden.be/wp-content/uploads/image250.png" width="481" height="360" /> </p>
<p>&#160;</p>
<h2>Adding Data From Another Database</h2>
<p>Imagine now that you need to add an extra line under each product, containing the product description.&#160; But this description is not available in the data warehouse.&#160; In fact it could even be stored on another server.</p>
<p>In the example here we will retrieve the description from the AdventureWorks2008R2 relational database.</p>
<h3>Setting Up The Second Dataset</h3>
<p>I’ve created an additional dataset called dsProductInfo, using the following query:</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: blue">select </span>P<span style="color: gray">.</span>ProductNumber<span style="color: gray">, </span>PD<span style="color: gray">.</span><span style="color: blue">Description
from </span>Production<span style="color: gray">.</span>Product P
<span style="color: gray">inner join </span>Production<span style="color: gray">.</span>ProductModel PM <span style="color: blue">on </span>P<span style="color: gray">.</span>ProductModelID <span style="color: gray">= </span>PM<span style="color: gray">.</span>ProductModelID
<span style="color: gray">inner join </span>Production<span style="color: gray">.</span>ProductModelProductDescriptionCulture PMPDC
    <span style="color: blue">on </span>PMPDC<span style="color: gray">.</span>ProductModelID <span style="color: gray">= </span>PM<span style="color: gray">.</span>ProductModelID
    <span style="color: gray">and </span>PMPDC<span style="color: gray">.</span>CultureID <span style="color: gray">= </span><span style="color: red">'en'
</span><span style="color: gray">inner join </span>Production<span style="color: gray">.</span>ProductDescription PD
    <span style="color: blue">on </span>PMPDC<span style="color: gray">.</span>ProductDescriptionID <span style="color: gray">= </span>PD<span style="color: gray">.</span>ProductDescriptionID</pre>
<p><a href="http://11011.net/software/vspaste"></a>Not only does it retrieve the product’s description, we’re also fetching the ProductNumber.&#160; Here’s what part of the result looks like:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Result of product description query" border="0" alt="Result of product description query" src="http://blog.hoegaerden.be/wp-content/uploads/image251.png" width="462" height="153" /> </p>
<p>The reason that we’re retrieving ProductNumber as well is because it matches with the ProductAlternateKey which we’ve retrieved earlier in our first dataset.&#160; And this is very important because that’s the key on which we’re going to link the datasets.</p>
<h3>Using The Lookup Function</h3>
<p>I’ve added an additional row inside the Details group and inserted a <a title="The Power Of The Placeholder" href="http://blog.hoegaerden.be/2009/04/07/the-power-of-the-placeholder/">Placeholder</a> to retrieve the product’s description, using the new <a title="BOL2008R2: Lookup Function" href="http://msdn.microsoft.com/en-us/library/ee210575%28v=SQL.105%29.aspx" target="_blank">Lookup function</a>.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Additional row inside Details group" border="0" alt="Additional row inside Details group" src="http://blog.hoegaerden.be/wp-content/uploads/image252.png" width="543" height="150" /> </p>
<p>So, what does the Placeholder’s expression look like?&#160; Here it is:</p>
<pre class="code">=Lookup(
    Fields!ProductAlternateKey.Value,
    Fields!ProductNumber.Value,
    Fields!Description.Value,
    <span style="color: #a31515">&quot;dsProductInfo&quot;
</span>)</pre>
<p><a href="http://11011.net/software/vspaste"></a>As you can see, the Lookup function requires four parameters.</p>
<p>The first parameter is the key value in your current dataset, the dataset used by the table data region.&#160; In our case that’s the ProductAlternateKey field in the dsInternetSales dataset.</p>
<p>The second parameter is the name of the key field in the second dataset, the one on which the lookup will happen.&#160; In our case that’s the ProductNumber in the dsProductInfo dataset.</p>
<p>The third parameter is the field from the second dataset that you’re wanting to retrieve using the lookup, in our case the Description field from dsProductInfo.</p>
<p>And finally, the last parameter is the name of the dataset on which you want to do the lookup.</p>
<p>Please note that parameter number four is a string parameter, so the value needs to be enclosed by double quotes.&#160; If you forget about that, you’ll get a couple of nice error messages like these:</p>
<blockquote>
<p>[rsInvalidLookupScope]&#160; The Value expression for the textrun ‘Textbox29.Paragraphs[0].TextRuns[0]’ has a scope parameter that is not valid for a lookup function. The scope parameter must be set to a string constant that is the name of a dataset.</p>
</blockquote>
<p>So, don’t forget the quotes.</p>
<p>With the Lookup call set up as explained, here’s the updated report Preview:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Rendered report with product descriptions added through Lookup" border="0" alt="Rendered report with product descriptions added through Lookup" src="http://blog.hoegaerden.be/wp-content/uploads/image253.png" width="518" height="594" /> </p>
<p>How cool is that huh?&#160; Each product has gotten a description, retrieved from another database, and still in the same table data region.&#160; Before R2 of SQL Server 2008, this wasn’t possible to achieve (well, not easily anyway) and now it’s actually fairly simple!</p>
<p>Is that all?&#160; Ha, I was kinda hoping that you were going to ask that.&#160; No, it’s not all, there are two more new lookup functions: LookupSet and MultiLookup.</p>
<h3>More Lookups: The LookupSet Function</h3>
<p>In case you’re wondering, in the Expression Builder the new lookup functions are located under the Miscellaneous node:</p>
<p><a href="http://blog.hoegaerden.be/wp-content/uploads/image254.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Expression Builder: the new lookup functions are under Miscellaneous" border="0" alt="Expression Builder: the new lookup functions are under Miscellaneous" src="http://blog.hoegaerden.be/wp-content/uploads/image_thumb61.png" width="682" height="231" /></a> </p>
<p>Let’s say that you want to add another detail row, this time it needs to show all colors in which the product is manufactured.&#160; Again this additional info is coming from the AdventureWorks relational database.</p>
<p>I’ve created a dataset called dsProductColors using the following query:</p>
<pre class="code"><span style="color: blue">select distinct </span><span style="color: gray">LEFT(</span>P<span style="color: gray">.</span>ProductNumber<span style="color: gray">, </span>6<span style="color: gray">) </span><span style="color: blue">as </span>ProductCodeWithoutColorAndSize<span style="color: gray">,
    </span>P<span style="color: gray">.</span>Color
<span style="color: blue">from </span>Production<span style="color: gray">.</span>Product P
<span style="color: blue">where </span>P<span style="color: gray">.</span>Color <span style="color: gray">is not null</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>When looking at the product codes, I noticed that for the products which are available in several colors and sizes, the last four characters represent the color and size.&#160; Which means the first six characters define the product itself, without color or size.&#160; That’s why the query is using the Left function to create a product code of only the first six characters of the ProductNumber.&#160; Using the distinct keyword, we remove any duplicate records.</p>
<p>(Please note that I’m not 100% sure if this logic applies to all products but for this demo it’s fine.)</p>
<p>Here’s what the query retrieves:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="List of product colors per product" border="0" alt="List of product colors per product" src="http://blog.hoegaerden.be/wp-content/uploads/image255.png" width="264" height="321" /> </p>
<p>As you can see, for some products there’s more than one record.&#160; And that’s exactly what the <a title="BOL2008R2: LookupSet Function" href="http://msdn.microsoft.com/en-us/library/ee210576%28v=SQL.105%29.aspx" target="_blank">LookupSet function</a> was made for: it retrieves a set of data based on the key given to it.&#160; This is different from the Lookup, where for each key value it would fetch only one value.</p>
<p>Again I’ve added an additional row inside the Details group and used a placeholder with the following expression:</p>
<pre class="code">=Join(
    LookupSet(
        Left(Fields!ProductAlternateKey.Value, 6),
        Fields!ProductCodeWithoutColorAndSize.Value,
        Fields!Color.Value,
        <span style="color: #a31515">&quot;dsProductColors&quot;
    </span>),
    <span style="color: #a31515">&quot;, &quot;
</span>)</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The LookupSet call itself looks very similar to the Lookup, with the same four parameters.&#160; I’ve used the Left function on the first parameter to apply the same logic to the ProductAlternateKey as we did with the ProductNumber.</p>
<p>However, there’s one important difference: the call of the Join function.&#160; This is needed because the LookupSet is returning a set, or better, a VariantArray, not just a single value.&#160; And an array cannot be visualized without first concatenating the values somehow.&#160; With the Join, we can concatenate the different values, using a comma as separator.</p>
<p>And here’s the resulting report:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Our report displaying the list of colors for each product" border="0" alt="Our report displaying the list of colors for each product" src="http://blog.hoegaerden.be/wp-content/uploads/image256.png" width="519" height="341" /> </p>
<p>With the first two lookup functions covered there’s one more to go.</p>
<h3>Just One More Lookup: The MultiLookup Function</h3>
<p>Guess what crazy request the business people have come up with this time?!&#160; The report should have a multi-value filter on region, and for each region selected, the top of the table should list the number of shops opened in the first year in those regions.&#160; For example, if the first shop in France was opened in 1970 and in that same year there were two other shops opened in France, the report should state “France: 3 shop(s) opened in 1970”.</p>
<p>Ow, and that list should be located right under the main header so deciding to use a textbox outside of the table is not a good idea <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Sounds like we can use the <a title="BOL2008R2: Multilookup Function" href="http://msdn.microsoft.com/en-us/library/ee210583%28v=SQL.105%29.aspx" target="_blank">MultiLookup</a> function for this request.&#160; But let’s first set up the filter.</p>
<p>I’ve created a dataset called dsRegions, using the following query on the data warehouse:</p>
<pre class="code"><span style="color: blue">select </span>DST<span style="color: gray">.</span>SalesTerritoryAlternateKey<span style="color: gray">,
    </span>DST<span style="color: gray">.</span>SalesTerritoryCountry <span style="color: gray">+ </span><span style="color: red">' - ' </span><span style="color: gray">+ </span>DST<span style="color: gray">.</span>SalesTerritoryRegion <span style="color: blue">as </span>CountryRegion
<span style="color: blue">from </span>DimSalesTerritory DST
<span style="color: blue">where </span>DST<span style="color: gray">.</span>SalesTerritoryAlternateKey <span style="color: gray">&gt; </span>0</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Then I’ve added a multi-value parameter called Regions with the Available Values coming from the dsRegions dataset.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Regions parameter: the Available Values" border="0" alt="Regions parameter: the Available Values" src="http://blog.hoegaerden.be/wp-content/uploads/image257.png" width="585" height="482" /> </p>
<p>This parameter can now be used in our main dataset.&#160; Here’s the updated query:</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: blue">select </span>PROD<span style="color: gray">.</span>EnglishProductName<span style="color: gray">, </span>PROD<span style="color: gray">.</span>ProductAlternateKey<span style="color: gray">, </span>PROD<span style="color: gray">.</span>ListPrice<span style="color: gray">,
    </span>PSC<span style="color: gray">.</span>EnglishProductSubcategoryName<span style="color: gray">, </span>PC<span style="color: gray">.</span>EnglishProductCategoryName<span style="color: gray">,
    </span>S<span style="color: gray">.</span>OrderQuantity<span style="color: gray">, </span>S<span style="color: gray">.</span>SalesAmount
<span style="color: blue">from </span>FactInternetSales S
<span style="color: gray">inner join </span>DimProduct PROD <span style="color: blue">on </span>S<span style="color: gray">.</span>ProductKey <span style="color: gray">= </span>PROD<span style="color: gray">.</span>ProductKey
<span style="color: gray">inner join </span>DimProductSubcategory PSC
    <span style="color: blue">on </span>PROD<span style="color: gray">.</span>ProductSubcategoryKey <span style="color: gray">= </span>PSC<span style="color: gray">.</span>ProductSubcategoryKey
<span style="color: gray">inner join </span>DimProductCategory PC <span style="color: blue">on </span>PSC<span style="color: gray">.</span>ProductCategoryKey <span style="color: gray">= </span>PC<span style="color: gray">.</span>ProductCategoryKey
<span style="color: gray">inner join </span>DimSalesTerritory DST <span style="color: blue">on </span>S<span style="color: gray">.</span>SalesTerritoryKey <span style="color: gray">= </span>DST<span style="color: gray">.</span>SalesTerritoryKey
<span style="color: blue">where </span>DST<span style="color: gray">.</span>SalesTerritoryAlternateKey <span style="color: gray">in (</span>@Regions<span style="color: gray">)</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>The only difference with the previous query are the two last lines: we add DimSalesTerritory to the joins and filter it on SalesTerritoryAlternateKey.</p>
<p>Don’t forget to set up the parameter.</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Setting up the parameter on dsInternetSales" border="0" alt="Setting up the parameter on dsInternetSales" src="http://blog.hoegaerden.be/wp-content/uploads/image258.png" width="600" height="234" /> </p>
<p>With the filter implemented, let’s get started on that extra lookup.&#160; </p>
<p>First we need to add the dataset containing the data that we need.&#160; I’ve created a dataset called dsShopsOpenedInFirstYear, using the following query on the relational database:</p>
<pre class="code"><span style="color: blue">with </span>ShopOpened <span style="color: blue">as
</span><span style="color: gray">(
    </span><span style="color: blue">select </span>T<span style="color: gray">.</span>TerritoryID<span style="color: gray">, </span>T<span style="color: gray">.</span>Name Territory<span style="color: gray">, </span>S<span style="color: gray">.</span>Name ShopName<span style="color: gray">,
        </span>S<span style="color: gray">.</span>[Demographics]<span style="color: gray">.</span>value<span style="color: gray">(</span><span style="color: red">'declare default element namespace &quot;http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey&quot;;
        (/StoreSurvey/YearOpened)[1]'</span><span style="color: gray">, </span><span style="color: red">'integer'</span><span style="color: gray">) </span><span style="color: blue">AS </span>[YearOpened]
    <span style="color: blue">from </span>Sales<span style="color: gray">.</span>Store S
    <span style="color: gray">inner join </span>Sales<span style="color: gray">.</span>SalesPerson SP <span style="color: blue">on </span>S<span style="color: gray">.</span>SalesPersonID <span style="color: gray">= </span>SP<span style="color: gray">.</span>BusinessEntityID
    <span style="color: gray">inner join </span>Sales<span style="color: gray">.</span>SalesTerritory T <span style="color: blue">on </span>SP<span style="color: gray">.</span>TerritoryID <span style="color: gray">= </span>T<span style="color: gray">.</span>TerritoryID
<span style="color: gray">),
</span>FirstShopOpened <span style="color: blue">as
</span><span style="color: gray">(
    </span><span style="color: blue">select </span><span style="color: magenta">MIN</span><span style="color: gray">(</span>YearOpened<span style="color: gray">) </span>YearOpened<span style="color: gray">, </span>TerritoryID
    <span style="color: blue">from </span>ShopOpened
    <span style="color: blue">group by </span>TerritoryID
<span style="color: gray">)
</span><span style="color: blue">select </span>SO<span style="color: gray">.</span>TerritoryID<span style="color: gray">,
    </span>SO<span style="color: gray">.</span>Territory <span style="color: gray">+ </span><span style="color: red">': ' </span><span style="color: gray">+ </span><span style="color: magenta">CAST</span><span style="color: gray">(</span><span style="color: magenta">COUNT</span><span style="color: gray">(*) </span><span style="color: blue">as varchar</span><span style="color: gray">(</span>100<span style="color: gray">)) +
    </span><span style="color: red">' shop(s) opened in ' </span><span style="color: gray">+ </span><span style="color: magenta">CAST</span><span style="color: gray">(</span>SO<span style="color: gray">.</span>YearOpened <span style="color: blue">as char</span><span style="color: gray">(</span>4<span style="color: gray">)) </span><span style="color: blue">as </span>ShopString
<span style="color: blue">from </span>FirstShopOpened FSO
<span style="color: gray">inner join </span>ShopOpened SO <span style="color: blue">on </span>SO<span style="color: gray">.</span>TerritoryID <span style="color: gray">= </span>FSO<span style="color: gray">.</span>TerritoryID
    <span style="color: gray">and </span>SO<span style="color: gray">.</span>YearOpened <span style="color: gray">= </span>FSO<span style="color: gray">.</span>YearOpened
<span style="color: blue">group by </span>SO<span style="color: gray">.</span>TerritoryID<span style="color: gray">, </span>SO<span style="color: gray">.</span>Territory<span style="color: gray">, </span>SO<span style="color: gray">.</span>YearOpened</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This query uses a couple of <a title="BOL2008: Using Common Table Expressions" href="http://msdn.microsoft.com/en-us/library/ms190766.aspx" target="_blank">Common Table Expressions</a> to get to the result as we need it.&#160; The first CTE, ShopOpened, creates a list of all shops with their territory and the opening year.&#160; The second CTE, FirstShopOpened uses the ShopOpened CTE to retrieve the first opening year for each territory.</p>
<p>And finally the main query uses both CTEs to create the following result:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Number of shops opened in first year per territory" border="0" alt="Number of shops opened in first year per territory" src="http://blog.hoegaerden.be/wp-content/uploads/image259.png" width="336" height="236" /> </p>
<p>For each territory we’ve constructed a string that shows how many shops were opened in the first year of that region, and in what year it happened.&#160; Coincidentally all regions had shops opened in 1970.</p>
<p>The TerritoryID corresponds with the SalesTerritoryAlternateKey, which is the value of our Regions parameter.</p>
<p>I’ve added an extra row under the top row in the table data region, and I’m using the following expression in that row:</p>
<pre class="code">=Join(
    MultiLookup(
        Parameters!Regions.Value,
        Fields!TerritoryID.Value,
        Fields!ShopString.Value,
        <span style="color: #a31515">&quot;dsShopsOpenedInFirstYear&quot;
    </span>),
    <span style="color: #a31515">&quot;&lt;br&gt;&quot;
</span>)</pre>
<p>The MultiLookup takes four parameters, just like the two previous lookup functions.&#160; They are all the same, except for the first one.&#160; It may not be very obvious in the example here, but the Parameters!Regions.Value is in fact not just a single value.&#160; It’s an array because we’ve set up the parameter as being multi-valued.</p>
<p>And that’s exactly what the MultiLookup function requires.&#160; Here’s the description for that first parameter, as stated in the Books Online:</p>
<blockquote>
<p>(<strong>VariantArray</strong>) An expression that is evaluated in the current scope and that specifies the set of names or keys to look up. For example, for a multivalue parameter, <code>=Parameters!IDs.value</code>.</p>
</blockquote>
<p>Just like the LookupSet function, MultiLookup returns a VariantArray, so we use the Join function to concatenate the values.</p>
<p>Interesting to note here is that I’m adding the break HTML tag as separator.&#160; I want the result of the expression to be treated as HTML, so that each value retrieved ends up at a new line in the textbox.&#160; To get this to work as expected, you need to tell the Placeholder that the resulting value should be treated as HTML:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Using HTML in a Placeholder" border="0" alt="Using HTML in a Placeholder" src="http://blog.hoegaerden.be/wp-content/uploads/image260.png" width="592" height="479" /> </p>
<p>Everything is now set up to have another report Preview.&#160; The following screenshot shows the report with the data filtered on Canada, France and Australia:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="The final report performing three different lookups" border="0" alt="The final report performing three different lookups" src="http://blog.hoegaerden.be/wp-content/uploads/image261.png" width="518" height="452" /> </p>
<p>Seems to be working fine, doesn’t it?</p>
<p>Okay, that’s it for now, have fun looking up that data!</p>
<p>Valentino.</p>
<p><strong>References</strong></p>
<p><a title="BOL2008R2: Lookup Function" href="http://msdn.microsoft.com/en-us/library/ee210575%28v=SQL.105%29.aspx" target="_blank">BOL2008R2: Lookup Function</a></p>
<p><a title="BOL2008R2: LookupSet Function" href="http://msdn.microsoft.com/en-us/library/ee210576%28v=SQL.105%29.aspx" target="_blank">BOL2008R2: LookupSet Function</a></p>
</p>
<p><a title="BOL2008R2: MultiLookup Function" href="http://msdn.microsoft.com/en-us/library/ee210583%28v=SQL.105%29.aspx" target="_blank">BOL2008R2: MultiLookup Function</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.hoegaerden.be%2F2010%2F05%2F16%2Flooking-up-data-on-different-sources%2F&amp;title=Looking%20Up%20Data%20On%20Different%20Sources" id="wpa2a_8"><img src="http://blog.hoegaerden.be/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.hoegaerden.be/2010/05/16/looking-up-data-on-different-sources/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

