<?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; Report Builder 2.0</title>
	<atom:link href="http://blog.hoegaerden.be/tag/report-builder-2-0/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>Adding an Else to your Switch</title>
		<link>http://blog.hoegaerden.be/2009/09/14/adding-an-else-to-your-switch/</link>
		<comments>http://blog.hoegaerden.be/2009/09/14/adding-an-else-to-your-switch/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 18:11:11 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Report Builder 2.0]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/09/14/adding-an-else-to-your-switch/</guid>
		<description><![CDATA[In this short article I will be talking about two functions in the SQL Server Reporting Services (SSRS) function stack.&#160; Those functions are IIF() and Switch().&#160; And I&#8217;ll be showing you how easy it is to add an Else part to the Switch function. Two commonly-used functions in Reporting Services are the IIF() and the [...]]]></description>
			<content:encoded><![CDATA[<p>In this short article I will be talking about two functions in the SQL Server Reporting Services (SSRS) function stack.&#160; Those functions are IIF() and Switch().&#160; And I&#8217;ll be showing you how easy it is to add an Else part to the Switch function.</p>
<p>Two commonly-used functions in Reporting Services are the<strong> IIF()</strong> and the <strong>Switch()</strong>.&#160; These are two functions of the Program Flow type, or Decision Functions as they are called on <a title="BOL 2008 - Expression Examples (Reporting Services)" href="http://msdn.microsoft.com/en-us/library/ms157328.aspx" target="_blank">this MSDN page</a>.</p>
<p>In case you’re wondering why it’s so difficult to find a function reference for the built-in functions of SSRS, it’s because these are actually Visual Basic functions and Microsoft refers to those for any detailed explanation.&#160; Click <a title="VB 2008 - IIf Function" href="http://msdn.microsoft.com/en-us/library/27ydhh0d.aspx" target="_blank">this link for the IIF() function</a> in the Visual Basic Language Reference, and <a title="VB 2008 - Switch Function" href="http://msdn.microsoft.com/en-us/library/dft2z9yf.aspx" target="_blank">this one for the Switch()</a>.</p>
<p>Anyone who’s done some programming most likely already knows the<strong> if &lt;expression&gt; then &lt;some_code&gt; else &lt;other_code&gt; </strong>statement.&#160; If &lt;expression&gt; evaluates to true then &lt;some_code&gt; gets executed, else &lt;other_code&gt;&#160; gets executed.</p>
<p>The <strong>IIF()</strong> works in the same way.&#160; According to its description it</p>
<blockquote><p><em>Returns one of two objects, depending on the evaluation of an expression.</em></p>
</blockquote>
<p>This is its definition:</p>
<pre class="code"><span style="color: blue">Public Function </span>IIf( _
<span style="color: blue">ByVal </span>Expression <span style="color: blue">As Boolean</span>, _
<span style="color: blue">ByVal </span>TruePart <span style="color: blue">As Object</span>, _
<span style="color: blue">ByVal </span>FalsePart <span style="color: blue">As Object </span>_
) <span style="color: blue">As Object</span></pre>
<p>Here’s a simple example:</p>
<pre class="code">=IIf(Fields!YearlyIncome.Value &gt;= 60000,<span style="color: #a31515">&quot;High&quot;</span>,<span style="color: #a31515">&quot;Low&quot;</span>)</pre>
<p>Using this expression, the &quot;High&quot; string is returned when the value of the YearlyIncome field is equal to or above 600, while the string &quot;Low&quot; is returned when the value is below 600.</p>
<p>Now have a look at the following example.&#160; It has been nicely structured with indentation and line breaks to make reading easier.</p>
<pre class="code">=IIF
(
    Sum(Fields!LineTotal.Value) &gt;= 100,
    <span style="color: #a31515">&quot;Violet&quot;</span>,
    IIF()
    (
        Sum(Fields!LineTotal.Value) &lt; 25,
        <span style="color: #a31515">&quot;Transparent&quot;</span>,
        <span style="color: #a31515">&quot;Cornsilk&quot;
    </span>)
)</pre>
<p>As you see, it shows a nested IIF inside another one.&#160; Imagine that there were several more nestings and that line breaks were not used by the coder.&#160; Would be a nightmare to read, right?</p>
<p>That’s why the <strong>Switch()</strong> was invented.&#160; The description for the Switch function reads:</p>
<blockquote>
<p><em>Evaluates a list of expressions and returns an Object value corresponding to the first expression in the list that is True.</em></p>
</blockquote>
<p>And this is the function definition:</p>
<pre class="code"><span style="color: blue">Public Function </span>Switch( _
    <span style="color: blue">ByVal ParamArray </span>VarExpr() <span style="color: blue">As Object </span>_
) <span style="color: blue">As Object</span></pre>
<p>In Reporting Services, the VarExpr parameter is simply an even list of expressions and/or object references separated by commas.&#160; Which comes down to something like this: <strong>Switch(&lt;expr1&gt;, val1, &lt;expr2&gt;, val2)</strong>.</p>
<p>Here’s a simple example:</p>
<pre class="code">=Switch
(
    Fields!State.Value = <span style="color: #a31515">&quot;OR&quot;</span>, <span style="color: #a31515">&quot;Oregon&quot;</span>,
    Fields!State.Value = <span style="color: #a31515">&quot;WA&quot;</span>, <span style="color: #a31515">&quot;Washington&quot;
</span>)</pre>
<p>This expression says that if the value for the State field is &quot;OR&quot; then the Switch function will return &quot;Oregon&quot;, and so on&#8230;</p>
<p>Now, to get to the point of this article, the Switch function does not contain an ELSE part like the IIF does.</p>
<p>But I wouldn’t be writing this if there wasn’t a workaround, would I?&#160; If you read the Switch’s description closely, it says that it will return <strong>the first expression in the list that is true</strong>.&#160; So each expression is evaluated in the order that they are passed to the function.&#160; To get ELSE-like behavior we would need an expression that evaluates to True but only when all other expressions are False.&#160; So, why not use True as expression?&#160; It’s the simplest expression that I can think of and it does the works!</p>
<p>Have a look at the following, it’s a rewrite of the last IIF example mentioned earlier.</p>
<pre class="code">=Switch
(
    Sum(Fields!LineTotal.Value) &gt;= 100, <span style="color: #a31515">&quot;Violet&quot;</span>,
    Sum(Fields!LineTotal.Value) &lt; 25, <span style="color: #a31515">&quot;Transparent&quot;</span>,
    <span style="color: blue">True</span>, <span style="color: #a31515">&quot;Cornsilk&quot;
</span>)</pre>
<p>So, which one do you think is the most readable?&#160; The IIF, or the Switch?&#160; These are only simple examples that I&#8217;ve been using, imagine situations with ten or more possibilities.&#160; Well, I think you&#8217;ve got my point by now.</p>
<p><strong>Quick tip for users of </strong><a title="Designing and Implementing Reports Using Report Builder 2.0" href="http://msdn.microsoft.com/en-us/library/dd220530.aspx" target="_blank"><strong>Report Builder 2.0</strong></a><strong>:</strong> to be able to format your expression with line breaks and tabs, you need to use CTRL + ENTER or CTRL + TAB in the Expression Builder.&#160; Just hitting ENTER will close the popup window.&#160; It’s quite annoying if you’re used to the BIDS interface, but it works <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Happy reporting,</p>
<p>Valentino.</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%2F2009%2F09%2F14%2Fadding-an-else-to-your-switch%2F&amp;title=Adding%20an%20Else%20to%20your%20Switch" 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/2009/09/14/adding-an-else-to-your-switch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Report Builder 2.0: Cannot switch data source</title>
		<link>http://blog.hoegaerden.be/2009/09/12/report-builder-2-0-cannot-switch-data-source/</link>
		<comments>http://blog.hoegaerden.be/2009/09/12/report-builder-2-0-cannot-switch-data-source/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 08:43:53 +0000</pubDate>
		<dc:creator>Valentino Vranken</dc:creator>
				<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[Report Builder 2.0]]></category>
		<category><![CDATA[Report Builder 3.0]]></category>
		<category><![CDATA[Reporting Services 2008]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://blog.hoegaerden.be/2009/09/12/report-builder-2-0-cannot-switch-data-source/</guid>
		<description><![CDATA[I came across an issue when playing around with Report Builder 2.0.  I had created a report using an embedded data source.  Once I’d published the report to the report server, I couldn’t get it to run anymore.  Instead it gave me the following error: This report cannot be run in report builder because it [...]]]></description>
			<content:encoded><![CDATA[<p>I came across an issue when playing around with Report Builder 2.0.  I had created a report using an embedded data source.  Once I’d published the report to the report server, I couldn’t get it to run anymore.  Instead it gave me the following error:</p>
<blockquote><p>This report cannot be run in report builder because it contains one or more embedded data sources with credential options that are not supported.  Instead of embedded data sources use shared data sources or save and view the report on the server.</p></blockquote>
<p>Okay, no problem I thought, let’s just create a shared data source and switch to that one then.  So I opened up the Data Source Properties in Report Builder and selected the <strong>Use a shared connection or report model</strong> radio button.</p>
<p>Unfortunately, when running the report it threw me that same error?!  And when I open the Data Source properties again, my change was undone!  It was still using the embedded data source.</p>
<p>As far as I’m concerned that should be a bug.</p>
<p>The only way that I could switch my data source to a shared connection was by creating a new data source, which means you also need to move all datasets connected to the original data source.</p>
<p>Quick tip: if you first rename the original data source and datasets to something like srcMyDataset_OLD, you can give the correct name to the new one straightaway.</p>
<p>So I guess that’s another workaround on my list <img src='http://blog.hoegaerden.be/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>This issue was encountered while using Report Builder 2.0 (10.0.2531.0).  I tried to reproduce it using Report Builder 3.0 (10.50.1092.20 – that’s the version of the SQL Server 2008 R2 August CTP) and I couldn’t.  Which means it has been fixed.  Good on you Microsoft!</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%2F2009%2F09%2F12%2Freport-builder-2-0-cannot-switch-data-source%2F&amp;title=Report%20Builder%202.0%3A%20Cannot%20switch%20data%20source" 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/2009/09/12/report-builder-2-0-cannot-switch-data-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

