<?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>tim laqua dot com &#187; bi</title>
	<atom:link href="http://timlaqua.com/tag/bi/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Sun, 09 May 2010 15:25:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Excel 2007 Hangs When Trying to Edit an OLAP Cube Filter</title>
		<link>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/</link>
		<comments>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 03:38:16 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[pivot table]]></category>
		<category><![CDATA[ssas]]></category>
		<category><![CDATA[xmla]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=371</guid>
		<description><![CDATA[Ok, it doesn't hang every time you try to edit an OLAP cube filter, but sometimes - it appears to. In reality, I've never seen it permanently hang - just kind of go away for a while. Here's the basic symptom that the business will report to you: "Excel freezes (or hangs) when I try [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, it doesn't hang every time you try to edit an OLAP cube filter, but sometimes - it appears to.  In reality, I've never seen it permanently hang - just kind of go away for a while.  Here's the basic symptom that the business will report to you:</p>
<p><em>"Excel freezes (or hangs) when I try to change this filter"</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png" alt="" title="DeliveryDate-Date-Broken" width="352" height="351" class="alignnone size-full wp-image-373" /></a></p>
<p>Most of us have seen this at one point or another and shrugged it off as a busy time or processing is going on or there are cats clogging up the tubes, etc.  Tonight, I finally decided to figure out what's causing it.<br />
<span id="more-371"></span><br />
When you have an OLAP cube filter in your pivot table and expand the items list to select your filter items, Excel fires a bunch of Discover commands at the cube (these are pretty light in most cases).  If you don't have anything selected yet (so you just have the default member selected) Excel isn't doing much work here and the list pops right up.  Here's two basic flow examples for what discover commands are fired off when you DO have an item selected:</p>
<p>If you have one level 1 member selected</p>
<ol>
<li>MDSCHEMA_CUBES (whatever cube you're connected to)</li>
<li>MDSCHEMA_CUBES (again, same thing)</li>
<li>MDSCHEMA_MEMBERS (LEVEL_UNIQUE_NAME of the filter), no TREE_OP</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member) TREE_OP 4, only immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 1, returns all children</li>
</ol>
<p>If you have one level 2 member selected in a hierarchy</p>
<ol>
<li>MDSCHEMA_CUBES (whatever cube you're connected to)</li>
<li>MDSCHEMA_CUBES (again, same thing)</li>
<li>MDSCHEMA_MEMBERS (LEVEL_UNIQUE_NAME of the filter), no TREE_OP</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member) TREE_OP 4, only immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent)  TREE_OP 4, immediate parent</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent's parent)  TREE_OP 1, all children</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 8, returns itself</li>
<li>MDSCHEMA_MEMBERS (MEMBER_UNIQUE_NAME of the selected member's parent) TREE_OP 1, returns all children</li>
</ol>
<p>So, that's six requests for a level 1 member and 9 requests for a level 2 member - both of these take milliseconds to complete the whole flow, so no big deal.  When does this become a big deal?  When you do something like click the "Select multiple items" checkbox, expand a hierarchy and UNCHECK something... like if you opened the Adventure Works 2008 cube, added Delivery Date.Date as a filter, expanded the "All Periods" level and deselected the first day:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Setup.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Setup.png" alt="" title="DeliveryDate-Date-Setup" width="312" height="418" class="alignnone size-full wp-image-372" /></a></p>
<p>Now click OK and expand the items box - we get a familiar popup:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Broken.png" alt="" title="DeliveryDate-Date-Broken" width="352" height="351" class="alignnone size-full wp-image-373" /></a></p>
<p>It comes back after a few seconds with the expected item list, but why did it take so long?  Well, based on our flows above, we have a whole bunch of level 1 members selected - 1187 of them to be exact.  That means there will be 1187 requests for their parent member (TREE_OP 4) which will all return the [All Periods] member.  To illustrate this, I traced that exact operation:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Profiler.png"><img src="http://timlaqua.com/wp-content/uploads/2010/04/DeliveryDate-Date-Profiler-300x144.png" alt="" title="DeliveryDate-Date-Profiler" width="300" height="144" class="alignnone size-medium wp-image-374" /></a></p>
<p>The profiler captured 1192 discover requests - 1187 of them were getting the parents of selected members, two were MDSCHEMA_CUBES requests, one was getting [All Periods], one was getting all the children of [All Periods], and one was getting the Unique Name of the root level.  Not cool.  Imagine what happens when your talking about tens of thousands of members at a particular level!  Granted, that seems unlikely but understand that the logic behind this is "I don't want to see this", "hide just this member", and so forth - in some cases people have no idea what actually happened was they unchecked one of 6,000 members.</p>
<p>So what to do about this?  Educate.  To fix the immediate problem of a seemingly broken Excel pivot table - just wait for the filter to load, it'll come back eventually.  In the future when working with Excel filters, always favor selecting vs. deselecting and filtering at higher levels in the hierarchy whenever possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/04/excel-2007-hangs-when-trying-to-edit-an-olap-cube-filter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clone Analysis Services Partitions with PowerShell</title>
		<link>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/</link>
		<comments>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 20:45:20 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[amo]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=322</guid>
		<description><![CDATA[Most of us with large Analysis Services cubes partition our cubes by month or year or some other time-based slice and we have all, at one point or another, developed some way to create partitions for new months on-demand. Often, the solution to this seems to be a C# console application or SSIS package using [...]]]></description>
			<content:encoded><![CDATA[<p>Most of us with large Analysis Services cubes partition our cubes by month or year or some other time-based slice and we have all, at one point or another, developed some way to create partitions for new months on-demand.  Often, the solution to this seems to be a C# console application or SSIS package using AMO to create a new partition based off an existing partition.  The problem I see with this is that maintaining it requires opening up the project or package, making changes, re-compiling, deploying, testing, deploying to production, verifying, etc.  It also requires that whoever is going to maintain it is comfortable with C#.</p>
<p>To simplify the maintenance and get rid of the "black box" factor that utility apps like this tend to have, I put together a PowerShell script to do the same thing and a stored procedure to call the script.  Really, it doesn't matter what you use as you're most likely using an almost identical chunk of code to get your new partition created - my argument is that using PowerShell instead of C# or SSIS reduces the cost of maintenance, improves readability, and facilitates better understanding throughout your team.<br />
<span id="more-322"></span><br />
<em>The PowerShell Script: cloneSSASPartition.ps1</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$ServerName</span><span style="color: pink;">,</span> 		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Analysis Services Instance #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$DatabaseName</span><span style="color: pink;">,</span> 		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Database our Cube is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$CubeName</span><span style="color: pink;">,</span>     		<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Cube that our Measure Group is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$MeasureGroupName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Measure Group that our Partition is in #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$SourcePartitionName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The name of the Partition we want to merge in to another partition #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$NewPartitionName</span><span style="color: pink;">,</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The desired name of the new partition #&gt;</span>
   <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$NewPartitionQuery</span> 	<span style="color: pink;">&lt;</span><span style="color: #008000;"># The Query source for the new partition (will use the same datasource as the SourcePartition #&gt;</span>
<span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.AnalysisServices&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span><span style="color: #800080;">$NULL</span>
&nbsp;
<span style="color: #800080;">$server</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.AnalysisServices.Server
<span style="color: #800080;">$server</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$ServerName</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$database</span> <span style="color: pink;">=</span> <span style="color: #800080;">$server</span>.Databases.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DatabaseName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$cube</span> <span style="color: pink;">=</span> <span style="color: #800080;">$database</span>.Cubes.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CubeName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$measureGroup</span> <span style="color: pink;">=</span> <span style="color: #800080;">$cube</span>.MeasureGroups.FindByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$MeasureGroupName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$sourcePartition</span> <span style="color: pink;">=</span> <span style="color: #800080;">$measureGroup</span>.Partitions.GetByName<span style="color: #000000;">&#40;</span><span style="color: #800080;">$SourcePartitionName</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$sourceQueryBinding</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sourcePartition</span>.Source
&nbsp;
<span style="color: #800080;">$newPartition</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sourcePartition</span>.Clone<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$newPartition</span>.ID <span style="color: pink;">=</span> <span style="color: #800080;">$NewPartitionName</span>
<span style="color: #800080;">$newPartition</span>.Name <span style="color: pink;">=</span> <span style="color: #800080;">$NewPartitionName</span>
<span style="color: #800080;">$measureGroup</span>.Partitions.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$newPartition</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">&gt;</span> <span style="color: #800080;">$NULL</span>
<span style="color: #800080;">$newPartition</span>.Source <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.AnalysisServices.QueryBinding<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sourceQueryBinding</span>.DataSourceID<span style="color: pink;">,</span> <span style="color: #800080;">$NewPartitionQuery</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$newPartition</span>.Update<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$server</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p><em>The stored procedure to call the script: [Utility_CloneSSASPartition_S01] - assumes you placed cloneSSASPartition.ps1 at the root of the C: drive.  If you put it elsewhere, update the proc to reflect the actual location.</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
GO
&nbsp;
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>
GO
&nbsp;
<span style="color: #008080;">/*************************************************************************************
***
*** Procedure:  		[Utility_CloneSSASPartition]
*** Purpose:		Executes PowerShell script to clone a SSAS partition
***			
***			
*** Author:		tl
*** Date Created:		2010-01-15
*** 
*** Revision History
*** Date		Author			Description
*** 2010-01-15	tl			Created
*************************************************************************************/</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Utility_CloneSSASPartition_S01<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
	@ServerName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@DatabaseName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@CubeName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@MeasureGroupName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@SourcePartitionName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@NewPartitionName <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>,
	@NewPartitionQuery <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span> 
&nbsp;
<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">DECLARE</span> @cmd <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SET</span> @cmd <span style="color: #808080;">=</span> 
	<span style="color: #FF0000;">'powershell.exe -Command &quot;&amp; {'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' C:<span style="color: #000099; font-weight: bold;">\c</span>loneSSASPartition.ps1'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -ServerName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @ServerName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -DatabaseName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @DatabaseName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -CubeName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @CubeName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -MeasureGroupName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @MeasureGroupName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -SourcePartitionName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @SourcePartitionName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -NewPartitionName:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @NewPartitionName <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span>
	<span style="color: #808080;">+</span> <span style="color: #FF0000;">' -NewPartitionQuery:<span style="color: #000099; font-weight: bold;">\&quot;</span>'</span> <span style="color: #808080;">+</span> @NewPartitionQuery <span style="color: #808080;">+</span> <span style="color: #FF0000;">'<span style="color: #000099; font-weight: bold;">\&quot;</span>}&quot;'</span>
&nbsp;
<span style="color: #0000FF;">PRINT</span> @cmd
<span style="color: #0000FF;">EXEC</span> xp_cmdshell @cmd</pre></div></div>

<p>And, finally, we execute it</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Utility_CloneSSASPartition_S01<span style="color: #808080;">&#93;</span>
	 @ServerName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TESTSERVER'</span>
	,@DatabaseName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TestDatabase'</span>
	,@CubeName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'TestCube'</span>
	,@MeasureGroupName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Measure Group'</span>
	,@SourcePartitionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Partition - 200912'</span>
	,@NewPartitionName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Test Partition - 201001'</span>
	,@NewPartitionQuery <span style="color: #808080;">=</span> <span style="color: #FF0000;">'SELECT * FROM dbo.FactTableMonth('</span><span style="color: #FF0000;">'1/1/2010'</span><span style="color: #FF0000;">', '</span><span style="color: #FF0000;">'2/1/2010'</span><span style="color: #FF0000;">')'</span></pre></div></div>

<p>Again, I'm not saying there's anything "wrong" with using C# or SSIS Packages to do this sort of thing, I'm just pointing out that C# isn't always the answer - especially when someone other than you needs to maintain this thing in the future.  Keep it simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/01/clone-analysis-services-partitions-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wouldn&#8217;t it be fun if Cubes could talk?</title>
		<link>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/</link>
		<comments>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 19:47:21 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[amo]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[cubes]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=291</guid>
		<description><![CDATA[I didn't say "wouldn't it be useful" because after putting a test together, asking a cube questions with no context tends to return answers that it probably shouldn't have returned. In BI, it is incredibly important to understand what exactly it is you're asking for - if we just say we want "sales" and return [...]]]></description>
			<content:encoded><![CDATA[<p>I didn't say "wouldn't it be useful" because after putting a test together, asking a cube questions with no context tends to return answers that it probably shouldn't have returned.  In BI, it is incredibly important to understand what exactly it is you're asking for - if we just say we want "sales" and return an answer, nobody really knows what we meant by "sales."  Sure, in various circles, "sales" means the same thing - but once you start talking to different areas, departments, etc - the meaning of the word starts to shift.</p>
<p>But I digress - asking cubes questions is still pretty fun and some of the random things it returns when you point it at your own cubes can be flat out hilarious.</p>
<p>Here's a few questions thrown at the Adventure Works cube in the Adventure Works DW 2008 Analysis Services database<br />
<span id="more-291"></span></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">what was sales for nichole nara
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])
$13,295.38
what were sales for nichole nara in cy 2004
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works]))
$2,419.06
what were sales for nichole nara in cy 2004 in north america
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])))
No Results Found
what were sales for nichole nara in cy 2004 for bikes
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Product].[Category].[Bikes]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM (SELECT {[Customer].[Customer].[Nichole Nara]} ON 0 FROM [Adventure Works])))
$2,384.07
what were sales in north america in fy 2003 for bikes
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Product].[Category].[Bikes]} ON 0 FROM (SELECT {[Date].[Fiscal Year].[FY 2003]} ON 0 FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM [Adventure Works])))
$1,739,306.95
sales for cy 2004 in cy q1, cy q2, and cy q4 in north america and canada
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America],[Customer].[Country].[Canada]} ON 0 FROM (SELECT {[Date].[Calendar Quarter of Year].[CY Q1],[Date].[Calendar Quarter of Year].[CY Q2],[Date].[Calendar Quarter of Year].[CY Q4]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM [Adventure Works])))
I don't know - Query Failure: Members belong to different hierarchies in the  function.
sales for cy 2004 in cy q1, cy q2, and cy q4 in north america
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Sales Territory].[Sales Territory Group].[North America]} ON 0 FROM (SELECT {[Date].[Calendar Quarter of Year].[CY Q1],[Date].[Calendar Quarter of Year].[CY Q2],[Date].[Calendar Quarter of Year].[CY Q4]} ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2004]} ON 0 FROM [Adventure Works])))
$3,967,371.16
sales between cy 2003 and cy 2004 for large resellers
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT [Large Resellers] ON 0 FROM (SELECT {[Date].[Calendar Year].[CY 2003]:[Date].[Calendar Year].[CY2004]} ON 0 FROM [Adventure Works]))
$19,561,960.04
sales for top 50 customers in fy 2004 in fy q1 and fy q3
SELECT {[Measures].[Internet Sales Amount]} ON 0  FROM (SELECT {[Date].[Fiscal Quarter of Year].[FY Q1],[Date].[Fiscal Quarter of Year].[FY Q3]} ON 0 FROM (SELECT {[Date].[Fiscal Year].[FY 2004]} ON 0 FROM (SELECT [Top 50 Customers] ON 0 FROM [Adventure Works])))
$177,263.41</pre></div></div>

<p>The above questions returned pretty much exactly what I was looking for except for the one that threw us an error about members belonging to different hierarchies.  That one was because "Canada" was in [Customer].[Country] and "north america" was in [Sales Territory].[Sales Territory Group].  Yeah, it was a dumb question because canada is in north america, but it illustrates that when you don't qualify things, you can get some pretty confusing results.</p>
<p><strong>How's it work?</strong></p>
<ol>
<li>Enumerate all the Attribute Values for each Attribute Hierarchy and store them as "keywords"</li>
<li>Get some input</li>
<li>Look for the aforementioned "keywords" in the input string</li>
<li>Construct an MDX query based on what "keywords" were found in the string</li>
<li>Make sure there aren't any extra (non-noise) words in the string</li>
<li>Run Query</li>
<li>Return Results</li>
</ol>
<p><strong>How the queries are constructed</strong></p>
<ul>
<li>Attribute Values just create a subcube - it creates a new nested subcube for each list, range, or named set it finds</li>
<li>It only supports one measure as written and it just selects that from whatever quagmire of subcubes it's created</li>
</ul>
<p>There are tons of issues with this methodology when we have role playing dimensions because the attribute values will be the same for these dimensions - so only the first one enumerated will get in (there's a way to ignore certain dimensions in the app.config - ignore all but one role playing dimension).  It throws away context and calls it "noise" - now that's dangerous;  if you throw away the context and just look for keywords, it's pretty easy to answer a question that wasn't really asked (oops).</p>
<p>As far as configuring this thing goes - take a look at the app.config and throw in appropriate values for your setup.  You'll have to tweak the *Pattern values to fit things you want to match or exclude in your particular cube.  It's configured for the Adventure Works cube right now, but I didn't work with it much - I just flat out excluded a few dims and hierarchies that would obviously confuse it.</p>
<p>Also note that, as written, it needs an Analysis Services 2008 cube.</p>
<p>Let me know if you want to give it a try and I'll be more than happy to work with you on configuring/modifying it for your setup.  Also post comments on interesting observations you have when asking cubes unqualified questions <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href='http://timlaqua.com/wp-content/uploads/2009/11/SmartCube.zip'>Download the VS 2008 Project: SmartCube.zip</a></p>
<p>Also note, the project uses an interface called IODoodad for getting questions and responding - this has two public methods, GetInput() and Respond().  The original theory here is that we could make an old-school IRC bot type thing.  We did manage to hook it to Yammer for its IO, respond to private messages and public messages prefixed with @cube, etc.  I didn't really explain the config for YammerIO (there's a custom config section for that that needs a bunch of OAuth stuff).  Again, if you're interested in getting that working, let me know and I'll post instructions.  The project above is set to use ConsoleIO.</p>
<p>I don't plan on doing any more development here, it was just a quick PoC to see what it looked like and get some initial feedback.  If anyone's interested in moving forward with it and making it smarter (the project arguably should have been titled DumbCube at this point), let me know so I can post a link to your work and fork away <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/11/wouldnt-it-be-fun-if-cubes-could-talk/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Charting Analysis Services 2008 Trace Events</title>
		<link>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/</link>
		<comments>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 15:05:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=273</guid>
		<description><![CDATA[The other day I was running some Analysis Services traces for some reason or another and ran across Chris Webb's post on (Visualising Analysis Services Trace Information in Reporting Services). After looking over that post, I thought it'd be interesting to visualize various types of processing, queries, etc - basically take a trace and then [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was running some Analysis Services traces for some reason or another and ran across Chris Webb's post on (<a href="http://cwebbbi.spaces.live.com/Blog/cns!7B84B0F2C239489A!1660.entry">Visualising Analysis Services Trace Information in Reporting Services</a>).  After looking over that post, I thought it'd be interesting to visualize various types of processing, queries, etc - basically take a trace and then graph out what happened and when.  Here's a few samples of what the project yielded:</p>
<ul>
<li style="color: red;">Red: <em>Cube Processing on a 2 Minute schedule</em></li>
<li style="color: green;">Green: <em>Cube Processing on a 1 hour schedule</em></li>
<li style="color: blue;">Blue: <em>Cube Processing on a 1 hour schedule</em></li>
<li style="color: black;">Black: <em>Query Activity</em></li>
</ul>
<p><em>Most of the activity here is from SSRS subscriptions firing around 8AM </em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/8AM-MSRS-Subscription-Processing.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/8AM-MSRS-Subscription-Processing-300x174.png" alt="8AM MSRS Subscription Processing" title="8AM MSRS Subscription Processing" width="300" height="174" class="alignnone size-medium wp-image-269" /></a><br />
<span id="more-273"></span><br />
<em>This is the report filtered to only show events that had a duration greater than 10,000 MS (10 seconds) - Red cube is a trouble maker</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/SSAS-Events-Longer-Than-10-Seconds.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/SSAS-Events-Longer-Than-10-Seconds-300x173.png" alt="SSAS Events Longer Than 10 Seconds" title="SSAS Events Longer Than 10 Seconds" width="300" height="173" class="alignnone size-medium wp-image-270" /></a></p>
<p><em>And this is general SSAS activity over a few hours with the nearly instant events filtered out</em><br />
<a href="http://timlaqua.com/wp-content/uploads/2009/10/General-SSAS-Activity-3-Hours.png"><img src="http://timlaqua.com/wp-content/uploads/2009/10/General-SSAS-Activity-3-Hours-300x173.png" alt="General SSAS Activity (3 Hours)" title="General SSAS Activity (3 Hours)" width="300" height="173" class="alignnone size-medium wp-image-271" /></a></p>
<p>The following query assumes that the trace data ended up in a table:</p>
<ul>
<li>@StartMillisecond: INT; <em>Minimum relative start time (millisecond value, kinda have to guess and check)</em></li>
<li>@EndMillisecond: INT; <em>Maximum relative start time (millisecond value, kinda have to guess and check)</em></li>
<li>@MinDuration: INT; <em>Minimum duration in milliseconds</em></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">;WITH <span style="color: #66cc66;">&#91;</span>ProcessEvent<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	<span style="color: #ff0000;">'Process'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:DatabaseID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:DimensionID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> XML<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span>value
		<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'declare namespace B=&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;;           
		(//B:MeasureGroupID)[1]'</span>
		<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'VARCHAR(1024)'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>MeasureGroupId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> dbo<span style="color: #66cc66;">.</span>zTrace_MSAS_20091023_2 T
<span style="color: #993333; font-weight: bold;">WHERE</span> 
	T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventClass<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">16</span> 
	<span style="color: #993333; font-weight: bold;">AND</span> T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventSubclass<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">12</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#91;</span>TextData<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%Process%'</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>QueryEvent<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	<span style="color: #ff0000;">'Query'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>DatabaseName<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>MeasureGroupId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> dbo<span style="color: #66cc66;">.</span>zTrace_MSAS_20091023_2 T
<span style="color: #993333; font-weight: bold;">WHERE</span> T<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>EventClass<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">10</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">AS</span>
<span style="color: #66cc66;">&#40;</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>ProcessEvent<span style="color: #66cc66;">&#93;</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>QueryEvent<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span>
	 ROW_NUMBER<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> OVER <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>EventId<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>DATEADD<span style="color: #66cc66;">&#40;</span>HOUR<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#91;</span>RelativeStartTime<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Duration<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#91;</span>DatabaseID<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">,</span>CASE
		WHEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #ff0000;">'Dimension'</span>
		WHEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #ff0000;">'Measure Group'</span>
		ELSE <span style="color: #ff0000;">'None'</span>
	 END <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>ObjectType<span style="color: #66cc66;">&#93;</span>	<span style="color: #66cc66;">,</span>CASE
		WHEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #66cc66;">&#91;</span>DimensionID<span style="color: #66cc66;">&#93;</span>
		WHEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> THEN <span style="color: #66cc66;">&#91;</span>MeasureGroupID<span style="color: #66cc66;">&#93;</span>
		ELSE <span style="color: #ff0000;">'None'</span>
	 END <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>ObjectId<span style="color: #66cc66;">&#93;</span>	
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span>
	DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;=</span> @StartMillisecond
	<span style="color: #993333; font-weight: bold;">AND</span> DATEDIFF<span style="color: #66cc66;">&#40;</span>MILLISECOND<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> MIN<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> Event<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#91;</span>StartTime<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> @EndMillisecond
	<span style="color: #993333; font-weight: bold;">AND</span> Duration <span style="color: #66cc66;">&gt;=</span> @MinDuration</pre></div></div>

<p>A few notes on the report:</p>
<ul>
<li>[EventId] is the Series Group</li>
<li>This is a Range chart type, the Bottom value was [RelativeStartTime] and the Top value was [RelativeStartTime] + [Duration]</li>
<li>Coloring the series and markers uses the following expression

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">=</span>Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span><span style="color: #0600FF;">Event</span>.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Process&quot;</span>
	,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SSASDB&quot;</span>
		,<span style="color: #666666;">&quot;Red&quot;</span>
		,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;OtherSSASDB&quot;</span>
			,<span style="color: #666666;">&quot;Green&quot;</span>
			,Iif<span style="color: #000000;">&#40;</span>Fields<span style="color: #008000;">!</span>DatabaseID.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;YetAnotherSSASDB&quot;</span>
				,<span style="color: #666666;">&quot;Blue&quot;</span>
				,<span style="color: #666666;">&quot;Pink&quot;</span>
			<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#41;</span>
	,<span style="color: #666666;">&quot;Black&quot;</span>
<span style="color: #000000;">&#41;</span></pre></div></div>

</li>
</ul>
<p>And that's about it - if you have any more questions about it just let me know.  Just seemed like an interesting way to look at trace data <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   It also wouldn't be that difficult to generate events for other things, like your ETL processing and such so you could see that on top of everything else.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/10/charting-analysis-services-2008-trace-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reporting Services (SSRS/MSRS) 2008 Error: Set used with the complement operator must have all members from the same level</title>
		<link>http://timlaqua.com/2009/10/reporting-services-ssrsmsrs-2008-error-set-used-with-the-complement-operator-must-have-all-members-from-the-same-level/</link>
		<comments>http://timlaqua.com/2009/10/reporting-services-ssrsmsrs-2008-error-set-used-with-the-complement-operator-must-have-all-members-from-the-same-level/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 19:38:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[mdx]]></category>
		<category><![CDATA[msrs]]></category>
		<category><![CDATA[reporting services]]></category>
		<category><![CDATA[ssrs]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=244</guid>
		<description><![CDATA[When you use the Not In operator in a SSRS 2008 MDX query filter to exclude a named set, it uses a the complement operator in the constructed MDX. This is fine as long as "all members [are] from the same level." Since you got this error, they are not You can get around this [...]]]></description>
			<content:encoded><![CDATA[<p>When you use the <strong>Not In</strong> operator in a SSRS 2008 MDX query filter to exclude a named set, it uses a the complement operator in the constructed MDX.  This is fine as long as "all members [are] from the same level."  Since you got this error, they are not <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   You can get around this by using the Except() MDX function instead of letting SSRS use the Complement operator</p>
<p>In the ReportServerService log, you'll see something like this:<br />
<em>Microsoft.AnalysisServices.AdomdClient.AdomdErrorResponseException: Query (..., ...) Set used with the complement operator must have all members from the same level.</em></p>
<p><u>Original filter</u><br />
Dimension: <strong>Time</strong><br />
Hierarchy: <strong>Calendar Date</strong><br />
Operator: <strong>Not In</strong><br />
Filter Expression: <strong>[Today]</strong></p>
<p><u>New filter</u><br />
Dimension: <strong>Time</strong><br />
Hierarchy: <strong>Calendar Date</strong><br />
Operator: <strong>MDX</strong><br />
Filter Expression: <strong>Except([Time].[Calendar Date].[Calendar Date].MEMBERS, [Today])</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/10/reporting-services-ssrsmsrs-2008-error-set-used-with-the-complement-operator-must-have-all-members-from-the-same-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintaining a Type 1 Slowly Changing Dimension (SCD) using T-SQL</title>
		<link>http://timlaqua.com/2009/05/maintaining-a-type-1-slowly-changing-dimension-scd-using-t-sql/</link>
		<comments>http://timlaqua.com/2009/05/maintaining-a-type-1-slowly-changing-dimension-scd-using-t-sql/#comments</comments>
		<pubDate>Sat, 23 May 2009 16:37:35 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[data warehouse]]></category>
		<category><![CDATA[scd]]></category>
		<category><![CDATA[slowly changing dimension]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=224</guid>
		<description><![CDATA[A few days ago, one of our SSIS packages that maintained a Type 1 Slowly Changing Dimension (SCD) of about 1 million rows crept up to 15 minutes of runtime. Now this doesn't sound too bad, but this is part of our hourly batches, so 15 minutes is 25% of our entire processing window. The [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, one of our SSIS packages that maintained a Type 1 Slowly Changing Dimension (SCD) of about 1 million rows crept up to 15 minutes of runtime.  Now this doesn't sound too bad, but this is part of our hourly batches, so 15 minutes is 25% of our entire processing window.  The package was using the Slowly Changing Dimension Wizard transformation - we were doing the standard OLEDB Source (which basically represented how the SCD "should" look) and then sending it to the SCD transform and letting it figure out what needed to be inserted and updated.  One option was to switch to lookups instead of the SCD wizard to speed things up, maybe even some fancy checksum voodoo for the updates (see <a href="http://blog.stevienova.com/2008/11/22/ssis-slowly-changing-dimensions-with-checksum/">http://blog.stevienova.com/2008/11/22/ssis-slowly-changing-dimensions-with-checksum/</a> for an example).  Then after thinking about it a little more - why are we sending a million rows down the pipeline every hour?  We know only a small percentage of these are new - and another small percentage needs to be updated.  Well, we can just write a quick SQL query to get us just those sets and the package would be much more efficient!  </p>
<p>Wait a tick - why would we give the rows to SSIS if all it is going to do insert one set and update the other?  Let's just do it all in T-SQL:<span id="more-224"></span></p>
<p><em>The following tables and dim are fictional - I just need to make up a star schema DIM to illustrate the approach</em></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #Temp_SCDInserts <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>PartId<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span><span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- INSERTS for new Parts</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #Temp_SCDInserts
<span style="color: #0000FF;">SELECT</span>   
	<span style="color: #808080;">&#91;</span>PartId<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> 
	Part a <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartType b <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartTypeId</span> <span style="color: #808080;">=</span> b.<span style="color: #202020;">PartTypeId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplier c <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartSupplierId</span> <span style="color: #808080;">=</span> c.<span style="color: #202020;">PartSupplierId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplierCategory d <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> c.<span style="color: #202020;">PartSupplierCategoryId</span> <span style="color: #808080;">=</span> d.<span style="color: #202020;">PartSupplierCategoryId</span>
<span style="color: #0000FF;">EXCEPT</span>
<span style="color: #0000FF;">SELECT</span>
	<span style="color: #808080;">&#91;</span>PartId<span style="color: #808080;">&#93;</span>	
<span style="color: #0000FF;">FROM</span>
	DW.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Dim_Part</span> <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #008080;">-- UPDATES</span>
<span style="color: #0000FF;">SELECT</span> 
	 dim.<span style="color: #808080;">&#91;</span>PartKeyId<span style="color: #808080;">&#93;</span>
	,a.<span style="color: #808080;">&#91;</span>PartName<span style="color: #808080;">&#93;</span>
	,b.<span style="color: #808080;">&#91;</span>PartTypeId<span style="color: #808080;">&#93;</span>
	,b.<span style="color: #808080;">&#91;</span>PartTypeName<span style="color: #808080;">&#93;</span>
	,c.<span style="color: #808080;">&#91;</span>PartSupplierId<span style="color: #808080;">&#93;</span>
	,c.<span style="color: #808080;">&#91;</span>PartSupplierName<span style="color: #808080;">&#93;</span>
	,d.<span style="color: #808080;">&#91;</span>PartSupplierCategoryId<span style="color: #808080;">&#93;</span>
	,d.<span style="color: #808080;">&#91;</span>PartSupplierCategoryName<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">INTO</span> #Temp_SCDUpdates
<span style="color: #0000FF;">FROM</span> DW.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Dim_Part</span> dim <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Part a <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
		<span style="color: #0000FF;">ON</span> dim.<span style="color: #202020;">PartId</span> <span style="color: #808080;">=</span> a.<span style="color: #202020;">PartId</span> <span style="color: #008080;">-- Business Key</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartType b <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartTypeId</span> <span style="color: #808080;">=</span> b.<span style="color: #202020;">PartTypeId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplier c <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartSupplierId</span> <span style="color: #808080;">=</span> c.<span style="color: #202020;">PartSupplierId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplierCategory d <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> c.<span style="color: #202020;">PartSupplierCategoryId</span> <span style="color: #808080;">=</span> d.<span style="color: #202020;">PartSupplierCategoryId</span>
<span style="color: #0000FF;">WHERE</span>
	dim.<span style="color: #202020;">PartName</span> <span style="color: #808080;">&lt;&gt;</span> a.<span style="color: #202020;">PartName</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartTypeId</span> <span style="color: #808080;">&lt;&gt;</span> b.<span style="color: #202020;">PartTypeId</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartTypeName</span> <span style="color: #808080;">&lt;&gt;</span> b.<span style="color: #202020;">PartTypeName</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartSupplierId</span> <span style="color: #808080;">&lt;&gt;</span> c.<span style="color: #202020;">PartSupplierId</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartSupplierName</span> <span style="color: #808080;">&lt;&gt;</span> c.<span style="color: #202020;">PartSupplierName</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartSupplierCategoryId</span> <span style="color: #808080;">&lt;&gt;</span> d.<span style="color: #202020;">PartSupplierCategoryId</span>
	<span style="color: #808080;">OR</span> dim.<span style="color: #202020;">PartSupplierCategoryName</span>	<span style="color: #808080;">&lt;&gt;</span> d.<span style="color: #202020;">PartSupplierCategoryName</span>
&nbsp;
<span style="color: #008080;">-- INSERT new records</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> <span style="color: #808080;">&#91;</span>DW<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Dim_Part<span style="color: #808080;">&#93;</span>
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>PartId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartTypeId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartTypeName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierCategoryId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierCategoryName<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">SELECT</span> 
	 a.<span style="color: #808080;">&#91;</span>PartId<span style="color: #808080;">&#93;</span>
	,a.<span style="color: #808080;">&#91;</span>PartName<span style="color: #808080;">&#93;</span>
	,b.<span style="color: #808080;">&#91;</span>PartTypeId<span style="color: #808080;">&#93;</span>
	,b.<span style="color: #808080;">&#91;</span>PartTypeName<span style="color: #808080;">&#93;</span>
	,c.<span style="color: #808080;">&#91;</span>PartSupplierId<span style="color: #808080;">&#93;</span>
	,c.<span style="color: #808080;">&#91;</span>PartSupplierName<span style="color: #808080;">&#93;</span>
	,d.<span style="color: #808080;">&#91;</span>PartSupplierCategoryId<span style="color: #808080;">&#93;</span>
	,d.<span style="color: #808080;">&#91;</span>PartSupplierCategoryName<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> #Temp_SCDInserts i
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Part a <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span>
		<span style="color: #0000FF;">ON</span> i.<span style="color: #202020;">PartId</span> <span style="color: #808080;">=</span> a.<span style="color: #202020;">PartId</span> <span style="color: #008080;">-- Business Key</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartType b <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartTypeId</span> <span style="color: #808080;">=</span> b.<span style="color: #202020;">PartTypeId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplier c <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartSupplierId</span> <span style="color: #808080;">=</span> c.<span style="color: #202020;">PartSupplierId</span>
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> PartSupplierCategory d <span style="color: #0000FF;">WITH</span><span style="color: #808080;">&#40;</span>NOLOCK<span style="color: #808080;">&#41;</span> 
		<span style="color: #0000FF;">ON</span> c.<span style="color: #202020;">PartSupplierCategoryId</span> <span style="color: #808080;">=</span> d.<span style="color: #202020;">PartSupplierCategoryId</span>
&nbsp;
<span style="color: #008080;">-- UPDATE existing records</span>
<span style="color: #0000FF;">UPDATE</span> <span style="color: #808080;">&#91;</span>DW<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Dim_Part<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">SET</span>
	 <span style="color: #808080;">&#91;</span>PartName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartTypeId<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartTypeId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartTypeName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartTypeName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierId<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartSupplierId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartSupplierName<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierCategoryId<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartSupplierCategoryId<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>PartSupplierCategoryName<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>PartSupplierCategoryName<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> 
	<span style="color: #808080;">&#91;</span>DW<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>Dim_Part<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">AS</span> a
	<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> #Temp_SCDUpdates <span style="color: #0000FF;">AS</span> b 
		<span style="color: #0000FF;">ON</span> a.<span style="color: #202020;">PartKeyId</span> <span style="color: #808080;">=</span> b.<span style="color: #202020;">PartKeyId</span>  <span style="color: #008080;">-- Join on Business Keys or Surrogate Key</span>
&nbsp;
&nbsp;
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #Temp_SCDInserts
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #Temp_SCDUpdates</pre></div></div>

<p>The results?  Our 15 minute SSIS package has been replaced with a few lines of T-SQL and it now runs in less than 90 seconds.  Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/05/maintaining-a-type-1-slowly-changing-dimension-scd-using-t-sql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quick Analysis of Cached Query Plans in SQL Server 2005</title>
		<link>http://timlaqua.com/2009/05/quick-analysis-of-cached-query-plans-in-sql-server-2005/</link>
		<comments>http://timlaqua.com/2009/05/quick-analysis-of-cached-query-plans-in-sql-server-2005/#comments</comments>
		<pubDate>Fri, 15 May 2009 21:55:03 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[hash match]]></category>
		<category><![CDATA[merge join]]></category>
		<category><![CDATA[nested loop]]></category>
		<category><![CDATA[query plan]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=207</guid>
		<description><![CDATA[I run this one pretty frequently when we need to figure out what procs are killing a complex ETL process and what exactly about them is making the server cry. So basically, if it's on the development server, I'll do a DBCC FREEPROCCACHE and a DBCC DROPCLEANBUFFERS, run the entire set of ETLs, then run [...]]]></description>
			<content:encoded><![CDATA[<p>I run this one pretty frequently when we need to figure out what procs are killing a complex ETL process and what exactly about them is making the server cry.  So basically, if it's on the development server, I'll do a <code>DBCC FREEPROCCACHE</code> and a <code>DBCC DROPCLEANBUFFERS</code>, run the entire set of ETLs, then run this query and then dig deeper in to the query plans that look suspect (high *Scan counts usually, sometimes lots of Hash Matches or Merge Joins).  On a production server, the clearing of the proc cache and dropcleanbuffers can be problematic so I'll often just run the query after a scheduled ETL run.  If you want to see the query plans mapped out visually, click on the query_plan value and SSMS will open up the XML.  Then save that XML file as a .sqlplan file.  Once you have that, close the XML and then open the .sqlplan file.<span id="more-207"></span></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span>
	 DatabaseName
	,ObjectName
	,<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		sum((/QP:ShowPlanXML/QP:BatchSequence/QP:Batch/QP:Statements/QP:StmtSimple/QP:QueryPlan/@CompileTime))'</span>,<span style="color: #FF0000;">'NVARCHAR(MAX)'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">FLOAT</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">/</span><span style="color: #000;">1000.0</span><span style="color: #808080;">/</span><span style="color: #000;">60.0</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>CompileTime<span style="color: #808080;">&#93;</span>
	,query_plan
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:ColumnsWithNoStatistics))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>ColumnsWithNoStatistics<span style="color: #808080;">&#93;</span>
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:TableScan))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>TableScan<span style="color: #808080;">&#93;</span>
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:IndexScan))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>IndexScan<span style="color: #808080;">&#93;</span>
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:RelOp[@PhysicalOp=&quot;Nested Loops&quot;]))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>NestedLoop<span style="color: #808080;">&#93;</span>
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:RelOp[@PhysicalOp=&quot;Hash Match&quot;]))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>HashMatch<span style="color: #808080;">&#93;</span>
	,query_plan.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'
		declare namespace QP=&quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&quot;;   
		count((//QP:RelOp[@PhysicalOp=&quot;Merge Join&quot;]))'</span>,<span style="color: #FF0000;">'INT'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>MergeJoin<span style="color: #808080;">&#93;</span>
<span style="color: #0000FF;">FROM</span> 
	<span style="color: #808080;">&#40;</span>	
		<span style="color: #0000FF;">SELECT</span>
			<span style="color: #FF00FF;">OBJECT_NAME</span><span style="color: #808080;">&#40;</span>st.<span style="color: #202020;">objectid</span>,st.<span style="color: #202020;">dbid</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> ObjectName,
			<span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>st.<span style="color: #202020;">dbid</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> DatabaseName,
			st.<span style="color: #202020;">dbid</span>,
			st.<span style="color: #202020;">objectid</span>,
			qs.<span style="color: #202020;">plan_handle</span>
		<span style="color: #0000FF;">FROM</span> 
			sys.<span style="color: #202020;">dm_exec_query_stats</span> <span style="color: #0000FF;">AS</span> qs
			<span style="color: #808080;">CROSS</span> APPLY sys.<span style="color: #202020;">dm_exec_sql_text</span><span style="color: #808080;">&#40;</span>qs.<span style="color: #202020;">sql_handle</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> st
		<span style="color: #0000FF;">WHERE</span>
			ObjectId <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>
		<span style="color: #0000FF;">GROUP</span> <span style="color: #0000FF;">BY</span>
			st.<span style="color: #202020;">dbid</span>,
			st.<span style="color: #202020;">objectid</span>,
			qs.<span style="color: #202020;">plan_handle</span>
	<span style="color: #808080;">&#41;</span> a
	<span style="color: #808080;">CROSS</span> APPLY sys.<span style="color: #202020;">dm_exec_query_plan</span><span style="color: #808080;">&#40;</span>plan_handle<span style="color: #808080;">&#41;</span> qp
<span style="color: #0000FF;">WHERE</span> DatabaseName <span style="color: #808080;">=</span> <span style="color: #FF0000;">'NameOfDatabase'</span>
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> DatabaseName, ObjectName</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/05/quick-analysis-of-cached-query-plans-in-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSAS Cube Action: Cells Target type, URL Action type Example</title>
		<link>http://timlaqua.com/2009/03/ssas-cube-action-cells-target-type-url-action-type-example/</link>
		<comments>http://timlaqua.com/2009/03/ssas-cube-action-cells-target-type-url-action-type-example/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 03:32:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[additional actions]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[cube action]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=165</guid>
		<description><![CDATA[Originally, we were charged with figuring out how to display SSAS cube measure descriptions via ToolTip in Excel 2007. If that's your plan, forget it - after some reading up on the interwebs, it appears that Excel doesn't even request the Description property. Additionally, if you want to add a description to Calculated Members, you [...]]]></description>
			<content:encoded><![CDATA[<p>Originally, we were charged with figuring out how to display SSAS cube measure descriptions via ToolTip in Excel 2007.  If that's your plan, forget it - after some reading up on the interwebs, it appears that Excel doesn't even request the Description property.  Additionally, if you want to add a description to Calculated Members, you have to hack it in (yuck).</p>
<p>So we went with a simple, albeit relatively crude (but effective), alternative - implementing a URL action for Cells so users can easily link out to a definition of the measure they're looking at.</p>
<p>Create a new action in your cube (Open up the cube definition, Actions tab) and configure similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Name: View Member Definition
&nbsp;
Action Target
    Target Type: Cells
    Target object: All cells
&nbsp;
Action Content
    Type: URL
    Action expression: &quot;http://i.domain.com/doc/Defs.aspx#&quot; 
                       + [Measures].CurrentMember.Name
&nbsp;
Additional Properties
    Invocation: Interactive
    Description: View Member Definition
    &quot;View Definition Of &quot; + [Measures].CurrentMember.Name + &quot;...&quot;
    Caption is MDX: True</pre></div></div>

<p>When you're finished, it should look something like this:<br />
<a href="http://timlaqua.com/wp-content/uploads/2009/03/ssascubecellsurlaction.png"><img src="http://timlaqua.com/wp-content/uploads/2009/03/ssascubecellsurlaction-300x243.png" alt="ssascubecellsurlaction" title="ssascubecellsurlaction" width="300" height="243" class="alignnone size-medium wp-image-166" /></a></p>
<p>For a possible way to implement the aforementioned Definitions.aspx, check out <a href="http://timlaqua.com/2009/03/scrolling-to-and-highlighting-anchor-target-via-javascript/">http://timlaqua.com/2009/03/scrolling-to-and-highlighting-anchor-target-via-javascript/</a> - which describes an early endpoint we used for this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/03/ssas-cube-action-cells-target-type-url-action-type-example/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Searching for keywords in all Reporting Services (SSRS) reports</title>
		<link>http://timlaqua.com/2008/09/searching-for-keywords-in-all-reporting-services-ssrs-reports/</link>
		<comments>http://timlaqua.com/2008/09/searching-for-keywords-in-all-reporting-services-ssrs-reports/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 16:03:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[rdl]]></category>
		<category><![CDATA[reporting services]]></category>
		<category><![CDATA[ReportingServices]]></category>
		<category><![CDATA[reports]]></category>
		<category><![CDATA[ssrs]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=38</guid>
		<description><![CDATA[During impact analysis for any changes to existing database tables, cube dimensions, cube measures, etc, it's nice to know which reports are going to horribly break before your end-users let you know about it All of the rdl content for reports uploaded to SSRS is stored in the ReportingServices database in the Content column of [...]]]></description>
			<content:encoded><![CDATA[<p>During impact analysis for any changes to existing database tables, cube dimensions, cube measures, etc, it's nice to know which reports are going to horribly break before your end-users let you know about it <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   All of the rdl content for reports uploaded to SSRS is stored in the ReportingServices database in the Content column of the Catalog table (in binary, of course) so here's what I came up with to get the list of soon to be broken reports:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#91;</span>Path<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> ContentText
<span style="color: #993333; font-weight: bold;">FROM</span>
<span style="color: #66cc66;">&#40;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">&#91;</span>Path<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> cast<span style="color: #66cc66;">&#40;</span>cast<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>content<span style="color: #66cc66;">&#93;</span><span style="color: #993333; font-weight: bold;">AS</span> varbinary<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #66cc66;">&#91;</span>ContentText<span style="color: #66cc66;">&#93;</span>
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#91;</span>catalog<span style="color: #66cc66;">&#93;</span> cat <span style="color: #993333; font-weight: bold;">WITH</span><span style="color: #66cc66;">&#40;</span>nolock<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">&#91;</span>type<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">2</span>
<span style="color: #66cc66;">&#41;</span> a
<span style="color: #993333; font-weight: bold;">WHERE</span> ContentText <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%ColumnName%'</span> 
	<span style="color: #993333; font-weight: bold;">OR</span> ContentText <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%columnname%'</span> 
	<span style="color: #993333; font-weight: bold;">OR</span> ContentText <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%MeasureName%'</span> 
	<span style="color: #993333; font-weight: bold;">OR</span> ContentText <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%AttributeName%'</span> 
	<span style="color: #993333; font-weight: bold;">OR</span> ContentText <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%etc...%'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/09/searching-for-keywords-in-all-reporting-services-ssrs-reports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic MDX queries in TSQL</title>
		<link>http://timlaqua.com/2008/07/dynamic-mdx-queries-in-tsql/</link>
		<comments>http://timlaqua.com/2008/07/dynamic-mdx-queries-in-tsql/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 00:15:13 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[mdx]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=37</guid>
		<description><![CDATA[Say you want to run the same MDX query for each row in a given rowset. I needed to do this for alerting purposes, where there were different alert thresholds for different attribute values in a given dimension attribute. After struggling with passing a variable to the query argument of the OPENROWSET command, I finally [...]]]></description>
			<content:encoded><![CDATA[<p>Say you want to run the same MDX query for each row in a given rowset.  I needed to do this for alerting purposes, where there were different alert thresholds for different attribute values in a given dimension attribute.  After struggling with passing a variable to the query argument of the OPENROWSET command, I finally found the documentation that clearly stated that the query argument CAN'T be a variable.  Or a concatination of a string and a variable.  I still don't understand why...  but the suggested workaround is to construct a giant TSQL string and run it using the EXEC command.</p>
<p>Ok - but how do we get the results of the query?  Basically, the only way to do this is to create a temporary table in the current scope and do an INSERT INTO that temp table in your giant TSQL query.  It all ends up looking something like this:<br />
<span id="more-37"></span></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">DECLARE @PercentOfAverage <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
DECLARE @Yesterday <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
DECLARE @SevenDayAverage <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> SliceName<span style="color: #66cc66;">,</span>Threshold
<span style="color: #993333; font-weight: bold;">INTO</span> <span style="color: #808080; font-style: italic;">#Temp_SliceList</span>
<span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #66cc66;">&#40;</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Slice1'</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'SliceName'</span><span style="color: #66cc66;">,</span> <span style="color: #66cc66;">.</span>8 <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'Threshold'</span>
	<span style="color: #993333; font-weight: bold;">UNION</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'Slice2'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0.9</span>
<span style="color: #66cc66;">&#41;</span> a
&nbsp;
DECLARE @tsql NVARCHAR<span style="color: #66cc66;">&#40;</span>MAX<span style="color: #66cc66;">&#41;</span>
&nbsp;
DECLARE @slice VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
DECLARE @threshold DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
DECLARE @slicecursor CURSOR
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @slicecursor <span style="color: #66cc66;">=</span> CURSOR <span style="color: #993333; font-weight: bold;">FOR</span>
	<span style="color: #993333; font-weight: bold;">SELECT</span> slicename<span style="color: #66cc66;">,</span>threshold <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #808080; font-style: italic;">#Temp_SliceList</span>
&nbsp;
OPEN @slicecursor
&nbsp;
FETCH NEXT <span style="color: #993333; font-weight: bold;">FROM</span> @slicecursor <span style="color: #993333; font-weight: bold;">INTO</span> @slice<span style="color: #66cc66;">,</span> @threshold
&nbsp;
WHILE <span style="color: #66cc66;">&#40;</span>@@FETCH_STATUS <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> 
BEGIN
&nbsp;
&nbsp;
	<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#Temp_MdxResults </span>
	  <span style="color: #66cc66;">&#40;</span>Yesterday DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
		SevenDayAverage DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
		PercentOfAverage DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">SET</span> @tsql <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'
INSERT INTO #Temp_MdxResults (Yesterday, SevenDayAverage, PercentOfAverage)
SELECT    ISNULL(&quot;[Measures].[Yesterday Foo]&quot;, 0) AS '</span><span style="color: #ff0000;">'Yesterday'</span><span style="color: #ff0000;">',
						ISNULL(&quot;[Measures].[Average 7-Day Foo]&quot;, 0) AS '</span><span style="color: #ff0000;">'SevenDayAverage'</span><span style="color: #ff0000;">',
						ISNULL(&quot;[Measures].[Percent Change]&quot;, 0) AS '</span><span style="color: #ff0000;">'PercentOfAverage'</span><span style="color: #ff0000;">'
			  FROM      OpenRowset('</span><span style="color: #ff0000;">'MSOLAP'</span><span style="color: #ff0000;">',
								   '</span><span style="color: #ff0000;">'DATA SOURCE=SERVER<span style="color: #000099; font-weight: bold;">\I</span>NSTANCE; Initial Catalog=SSASDB;'</span><span style="color: #ff0000;">','</span><span style="color: #ff0000;">'
WITH 
MEMBER Measures.[Yesterday Foo] AS SUM
(
	{
		StrToMember(&quot;[Time].[Calendar Date].[&quot; + VBA!format(VBA!dateadd(&quot;d&quot;,-1,VBA![date]()),&quot;yyyy-MM-dd 00:00:00&quot;) + &quot;]&quot;)
	},
	[Measures].[Foo]		
)
MEMBER Measures.[Average 7-Day Foo] AS AVG
(
	{
		StrToMember(&quot;[Time].[Calendar Date].[&quot; + VBA!format(VBA!dateadd(&quot;d&quot;,-2,VBA![date]()),&quot;yyyy-MM-dd 00:00:00&quot;) + &quot;]&quot;):StrToMember(&quot;[Time].[Calendar Date].[&quot; + VBA!format(VBA!dateadd(&quot;d&quot;,-9,VBA![date]()),&quot;yyyy-MM-dd 00:00:00&quot;) + &quot;]&quot;)
	},
	[Measures].[Foo]		
)
MEMBER Measures.[Percent Change] AS Measures.[Yesterday Foo]/Measures.[Average 7-Day Foo]
SELECT 
{Measures.[Yesterday Foo], Measures.[Average 7-day Foo], Measures.[Percent Change]} ON 0,
{
	[Slice Dimension].[Slice Attribute].&amp;['</span> <span style="color: #66cc66;">+</span> @slice <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">']
}ON 1
FROM [Cube]'</span><span style="color: #ff0000;">') a'</span>
&nbsp;
	EXEC <span style="color: #66cc66;">&#40;</span>@tsql<span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">SELECT</span>  
		@PercentOfAverage <span style="color: #66cc66;">=</span> CAST<span style="color: #66cc66;">&#40;</span>tot<span style="color: #66cc66;">.</span>PercentOfAverage <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
		@Yesterday <span style="color: #66cc66;">=</span> CAST<span style="color: #66cc66;">&#40;</span>tot<span style="color: #66cc66;">.</span>Yesterday <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
		@SevenDayAverage <span style="color: #66cc66;">=</span> CAST<span style="color: #66cc66;">&#40;</span>tot<span style="color: #66cc66;">.</span>SevenDayAverage <span style="color: #993333; font-weight: bold;">AS</span> DECIMAL<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #993333; font-weight: bold;">FROM</span>    <span style="color: #808080; font-style: italic;">#Temp_MdxResults tot</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #808080; font-style: italic;">#Temp_MdxResults</span>
&nbsp;
	<span style="color: #993333; font-weight: bold;">IF</span> @PercentOfAverage <span style="color: #66cc66;">&lt;</span> @Threshold 
		BEGIN
			<span style="color: #808080; font-style: italic;">--Do Something useful here</span>
&nbsp;
		END
	FETCH NEXT <span style="color: #993333; font-weight: bold;">FROM</span> @slicecursor <span style="color: #993333; font-weight: bold;">INTO</span> @slice<span style="color: #66cc66;">,</span> @threshold
END</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/07/dynamic-mdx-queries-in-tsql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
