<?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; ssas</title>
	<atom:link href="http://timlaqua.com/tag/ssas/feed/" rel="self" type="application/rss+xml" />
	<link>http://timlaqua.com</link>
	<description>Thoughts and Code from Tim Laqua</description>
	<lastBuildDate>Fri, 16 Mar 2012 16:48:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>SSAS Cache Isn&#8217;t Making Cents</title>
		<link>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/</link>
		<comments>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 23:12:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[business intelligence]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=888</guid>
		<description><![CDATA[I stole the pun from my Business Analyst, Mr. John Seiler Now on to my issue - when SSAS caches the value for my [Actual] measure, it seems to do so based on the results of the first query that requests that coordinate. In this particular cube, there's bunches of tiny fractions and depending on [...]]]></description>
			<content:encoded><![CDATA[<p>I stole the pun from my Business Analyst, Mr. John Seiler <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   Now on to my issue - when SSAS caches the value for my [Actual] measure, it seems to do so based on the results of the first query that requests that coordinate.  In this particular cube, there's bunches of tiny fractions and depending on how you slice it, it aggregates a little different.  This is a fun problem in itself, but the part that drives me (and the Finance department) crazy is that if you go and slice on something OTHER than that first query that created the cache, the values they see don't always add up to the "Grand Total" in Excel - aka. "All"</p>
<p>These are the queries used for this test:</p>
<p>Query A</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span></pre></div></div>

<p>Query B</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span>
	<span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> <span style="color: #0000FF;">Hierarchize</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #0000FF;">DrilldownLevel</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #333333;">[Account]</span>.<span style="color: #333333;">[Accounts]</span>.<span style="color: #333333;">[All]</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #66cc66;">,,,</span>INCLUDE_CALC_MEMBERS<span style="color: #003300; font-weight: bold;">&#41;</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">1</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span></pre></div></div>

<p>Query C</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
	<span style="color: #003300; font-weight: bold;">&#123;</span>Actual<span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span>
	<span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> <span style="color: #0000FF;">Hierarchize</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #0000FF;">DrilldownLevel</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[All]</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #66cc66;">,,,</span>INCLUDE_CALC_MEMBERS<span style="color: #003300; font-weight: bold;">&#41;</span><span style="color: #003300; font-weight: bold;">&#125;</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">1</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[GL]</span> 
CELL <span style="color: #FF00FF;">PROPERTIES</span> <span style="color: #CC00FF;">VALUE</span>
GO</pre></div></div>

<style>
td {vertical-align: top;}
</style>
<p>Results (Cache was cleared with ClearCache on the entire Database before each Series)</p>
<table cellpadding=0 cellspacing=0>
<tr>
<th>Series 1</th>
<th>Series 2</th>
<th>Series 3</th>
</tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-A.png" alt="" title="Series 1 - Query A" width="134" height="41" class="alignnone size-full wp-image-890" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-B.png" alt="" title="Series 2 - Query B" width="182" height="126" class="alignnone size-full wp-image-894" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-C.png" alt="" title="Series 3 - Query C" width="177" height="115" class="alignnone size-full wp-image-898" /></a>
  </td>
</tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-B.png" alt="" title="Series 1 - Query B" width="181" height="124" class="alignnone size-full wp-image-891" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-C.png" alt="" title="Series 2 - Query C" width="179" height="117" class="alignnone size-full wp-image-895" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-A.png" alt="" title="Series 3 - Query A" width="132" height="38" class="alignnone size-full wp-image-896" /></a>
  </td>
<tr>
<tr>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-C.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-1-Query-C.png" alt="" title="Series 1 - Query C" width="176" height="116" class="alignnone size-full wp-image-892" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-A.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-2-Query-A.png" alt="" title="Series 2 - Query A" width="136" height="39" class="alignnone size-full wp-image-893" /></a>
  </td>
<td>
<a href="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-B.png"><img src="http://timlaqua.com/wp-content/uploads/2012/02/Series-3-Query-B.png" alt="" title="Series 3 - Query B" width="182" height="143" class="alignnone size-full wp-image-897" /></a>
  </td>
<tr>
</table>
<p>So basically the Grand Total of this GL cube is a random number based on whoever sneaks the first query in after the cache is cleared (processing, sync, etc).</p>
<p>And for all of you that think the MDX script breaks everything everywhere - I did comment out my entire MDX script before running these tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2012/02/ssas-cache-isnt-making-cents/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Parallel Cube Processor 1.0</title>
		<link>http://timlaqua.com/2011/04/parallel-cube-processor-1-0/</link>
		<comments>http://timlaqua.com/2011/04/parallel-cube-processor-1-0/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 11:30:58 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=505</guid>
		<description><![CDATA[Parallel Cube Processor (PCP) is an application designed to process multiple Analysis Services databases at the same time. I originally wrote this application with the assumption that it would be blazing fast and essentially warp space and time. As it turns out, SSAS appears to be going as fast as possible at all times, so [...]]]></description>
			<content:encoded><![CDATA[<p>Parallel Cube Processor (PCP) is an application designed to process multiple Analysis Services databases at the same time.  I originally wrote this application with the assumption that it would be blazing fast and essentially warp space and time.  As it turns out, SSAS appears to be going as fast as possible at all times, so giving it more stuff to do doesn't really make the whole shebang faster - just different.  Play around with it, watch some performance counters - it's an interesting conundrum.  The application can handle parallelism using two methods.  </p>
<p>The first method is <strong>XMLAParallel</strong> - in this mode, the application constructs an XMLA command to process the specified number of databases inside of a Parallel element.  Only one XMLA command is issued at a time so the applicatoin will not submit another command until the longest processing job completes in each batch.  <span id="more-505"></span></p>
<p>The second method is <strong>Threaded</strong> - in this mode, the application creates the specified number of threads and each thread processes databases independantly of the other threads.  This allows all threads to remain busy at all times as a given thread will start processing the next unprocessed database as soon as it finishes processing the previous database.</p>
<p>It should be noted that because this app performs only ProcessFull at the database level, it is currently only suitable for processing a large number of small analysis services databases. The environment this was developed for has a process that generates and deploys metadata for over 250 small (< 100MB) ssas databases and we need to process them as quickly as possible.</p>
<p>If you have suggestions for features that would help the application be more useful to you, please post them in the Discussions area.</p>
<p>And yes, I probably should have called it "ParallelDatabaseProcessor." PCP was a cooler acronym.</p>
<p>The application and source code can be downloaded on Codeplex: <a href="http://pcp.codeplex.com/">Parallel Cube Processor</a></p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/04/parallel-cube-processor-1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing With Long Running SSAS Queries using Powershell</title>
		<link>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/</link>
		<comments>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 17:27:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[bi]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=462</guid>
		<description><![CDATA[So, your Analysis Services instance keeps eating all the memory on your server despite proper memory configuration? This happens when queries get too big for their britches - SSAS memory limits are basically soft limits. Whatever an active query requires in terms of resources, SSAS will attempt to provide it. Even if it has to [...]]]></description>
			<content:encoded><![CDATA[<p>So, your Analysis Services instance keeps eating all the memory on your server despite proper memory configuration?  This happens when queries get too big for their britches - SSAS memory limits are basically soft limits.  Whatever an active query requires in terms of resources, SSAS will attempt to provide it.  Even if it has to page the entire operating system out to disk to do it.  You can mitigate this with good cube design, better aggregations, user training, etc - but it's bound to happen.  When your cube gets big enough, one of your users will blow the entire server up.<span id="more-462"></span></p>
<p>First things fist - the original thought for this came form Chris Webb's article,  <a href="http://cwebbbi.wordpress.com/2008/12/04/killing-sessions-automatically-with-ssis/">Killing sessions automatically with SSIS</a>.  Now on to my solution - which is basically identical in theory, just implemented in PowerShell with an email notification at the end.</p>
<p><em>Create a SQL Agent job with a PowerShell step that runs the following script and schedule it to run every 30 seconds</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$asInstance</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;ssasinstance&quot;</span>;
<span style="color: #800080;">$emailServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1.2.3.4&quot;</span>;
<span style="color: #800080;">$fromAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$toAddress</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;you@yourcompany.com&quot;</span>;
<span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: pink;">=</span> <span style="color: #000000;">30000</span>;
<span style="color: #800080;">$bypassUserPattern</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;yourusername&quot;</span>;
<span style="color: #008000;">#======== END Config =========</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.Xmla&quot;</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #000000;">&#91;</span>Microsoft.AnalysisServices.xmla.xmlaclient<span style="color: #000000;">&#93;</span><span style="color: #800080;">$client</span> <span style="color: pink;">=</span> 
  <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.AnalysisServices.Xmla.XmlaClient ;
<span style="color: #800080;">$client</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$asInstance</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$commands</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$sessions</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_COMMANDS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$commands</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_SESSIONS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$sessions</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$sessionsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$sessions</span>;
<span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sessionsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
<span style="color: #800080;">$commandsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$commands</span>;
<span style="color: #800080;">$commandsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$commandsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$commandsRows</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span>
  <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$row</span>.COMMAND_ELAPSED_TIME_MS <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;SELECT&quot;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$spid</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.SESSION_SPID;
    <span style="color: #800080;">$commandText</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT;
    <span style="color: #800080;">$session</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.SESSION_SPID <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$spid</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$user</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_USER_NAME;
    <span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_CURRENT_DATABASE;
    <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$user</span> <span style="color: #FF0000;">-notmatch</span> <span style="color: #800080;">$bypassUserPattern</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
      <span style="color: #800080;">$cancelXMLA</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&lt;Cancel xmlns=&quot;</span><span style="color: #800000;">&quot;http://schemas.microsoft.com/analysisservices/2003/engine&quot;</span><span style="color: #800000;">&quot;&gt;&lt;SPID&gt;$spid&lt;/SPID&gt;&lt;/Cancel&gt;&quot;</span>;
      <span style="color: #800080;">$client</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$cancelXMLA</span><span style="color: pink;">,</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span>;
      <span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailServer</span><span style="color: #000000;">&#41;</span>; 
      <span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span>
        <span style="color: #800000;">&quot;$asInstance &lt;$fromAddress&gt;&quot;</span><span style="color: pink;">,</span> 
        <span style="color: #800080;">$toAddress</span><span style="color: pink;">,</span> 
        <span style="color: #800000;">&quot;Killed SPID: $spid&quot;</span><span style="color: pink;">,</span> 
        <span style="color: #800000;">&quot;SPID $spid was detected as the owner of a long running query and was killed.<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>User: $user<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>DB: $db<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span><span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>$commandText&quot;</span>
      <span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$client</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Great.  Now sessions with active queries (aka "commands" with the word "SELECT" in them) taking over 30 seconds will be cancelled and we'll get an email w/ the query so we can debug!  So you wake up the next morning and Japan called - a bunch of their pivots errored out last night and they're not happy.  Hmm...  Pry should have warned someone before we started cancelling queries...</p>
<p><strong>Phase 2:  Turn off the query/session killer, turn on the logging</strong></p>
<p>Create the Log table:</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> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>LongRunningMDXQueryLog<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span>
	<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">255</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">INT</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#93;</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span></pre></div></div>

<p>Create the MERGE proc to handle log entries</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;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>LongRunningMDXQueryLog_Merge<span style="color: #808080;">&#93;</span>
	 @SPID <span style="color: #0000FF;">INT</span>
	,@CommandStartTime <span style="color: #0000FF;">DATETIME</span>
	,@Username <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: #0000FF;">DATABASE</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>
	,@ElapsedTimeMS <span style="color: #0000FF;">INT</span>
	,@CommandText <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	;MERGE LongRunningMDXQueryLog a <span style="color: #0000FF;">USING</span>
	<span style="color: #808080;">&#40;</span>
		<span style="color: #0000FF;">SELECT</span>
			 @SPID 
			,<span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span>@CommandStartTime <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">DATETIME</span><span style="color: #808080;">&#41;</span>
			,@Username 
			,@<span style="color: #0000FF;">DATABASE</span>
			,@ElapsedTimeMS 
			,@CommandText 
	<span style="color: #808080;">&#41;</span> b
	<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
	,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">ON</span>
	<span style="color: #808080;">&#40;</span>a.<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
	 <span style="color: #808080;">AND</span> a.<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">THEN</span>
	<span style="color: #0000FF;">INSERT</span>
			   <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
		 <span style="color: #0000FF;">VALUES</span>
			   <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#91;</span>SPID<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandStartTime<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>Username<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">DATABASE</span><span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
			   ,<span style="color: #808080;">&#91;</span>CommandText<span style="color: #808080;">&#93;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">WHEN</span> MATCHED <span style="color: #0000FF;">THEN</span>
	<span style="color: #0000FF;">UPDATE</span>
	<span style="color: #0000FF;">SET</span>
		<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> b.<span style="color: #808080;">&#91;</span>ElapsedTimeMS<span style="color: #808080;">&#93;</span>
	;
<span style="color: #0000FF;">END</span></pre></div></div>

<p>Create a job to run the following Powershell script every 30 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#======= START Config ========</span>
<span style="color: #800080;">$asInstance</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;ssasinstance&quot;</span>;
<span style="color: #800080;">$logConnectionString</span> <span style="color: pink;">=</span> 
  <span style="color: #800000;">&quot;server=sqlserverinstance;&quot;</span> <span style="color: pink;">+</span> 
  <span style="color: #800000;">&quot;database=databaseYouCreatedTheLogTableIn;&quot;</span> <span style="color: pink;">+</span> 
  <span style="color: #800000;">&quot;trusted_connection=true;&quot;</span>;
<span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: pink;">=</span> <span style="color: #000000;">30000</span>;
<span style="color: #008000;">#======== END Config =========</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.Xmla&quot;</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #000000;">&#91;</span>Microsoft.AnalysisServices.xmla.xmlaclient<span style="color: #000000;">&#93;</span><span style="color: #800080;">$client</span> <span style="color: pink;">=</span> 
  <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.AnalysisServices.Xmla.XmlaClient ;
<span style="color: #800080;">$client</span>.Connect<span style="color: #000000;">&#40;</span><span style="color: #800080;">$asInstance</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$commands</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$sessions</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_COMMANDS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$commands</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$client</span>.Discover<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DISCOVER_SESSIONS&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">ref</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$sessions</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">0</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span> ;
<span style="color: #800080;">$sessionsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$sessions</span>;
<span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sessionsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
<span style="color: #800080;">$commandsXml</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">xml</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$commands</span>;
<span style="color: #800080;">$commandsRows</span> <span style="color: pink;">=</span> <span style="color: #800080;">$commandsXml</span>.<span style="color: #0000FF;">return</span>.root.row;
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$row</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$commandsRows</span><span style="color: #000000;">&#41;</span> 
<span style="color: #000000;">&#123;</span>
  <span style="color: #800080;">$elapsedTimeMS</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_ELAPSED_TIME_MS;
  <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$elapsedTimeMS</span> <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$maxQueryElapsedMS</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;SELECT&quot;</span><span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$spid</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.SESSION_SPID;
    <span style="color: #800080;">$commandText</span> <span style="color: pink;">=</span> <span style="color: #800080;">$row</span>.COMMAND_TEXT <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">&quot;'&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;''&quot;</span>;
    <span style="color: #800080;">$session</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$sessionsRows</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;"><span style="color: #000080;">$_</span></span>.SESSION_SPID <span style="color: #FF0000;">-eq</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$spid</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$user</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_USER_NAME;
    <span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800080;">$session</span>.SESSION_CURRENT_DATABASE;
    <span style="color: #800080;">$commandStartTime</span> <span style="color: pink;">=</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;">$row</span>.COMMAND_START_TIME <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">'\.\d+$'</span><span style="color: pink;">,</span> <span style="color: #800000;">''</span> <span style="color: #FF0000;">-replace</span> <span style="color: #800000;">'T'</span><span style="color: pink;">,</span> <span style="color: #800000;">' '</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlConn</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SQLClient.SQLConnection<span style="color: #000000;">&#40;</span><span style="color: #800080;">$logConnectionString</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlConn</span>.Open<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #800080;">$sqlCommand</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SQLClient.SQLCommand;
    <span style="color: #800080;">$sqlCommand</span>.Connection <span style="color: pink;">=</span> <span style="color: #800080;">$sqlConn</span>;
    <span style="color: #800080;">$sqlCommand</span>.CommandText <span style="color: pink;">=</span> 
      <span style="color: #800000;">&quot;EXEC LongRunningMDXQueryLog_Merge &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;$spid, &quot;</span> <span style="color: pink;">+</span>
        <span style="color: #800000;">&quot;'$commandStartTime', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$user', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$db', &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;$elapsedTimeMS, &quot;</span> <span style="color: pink;">+</span> 
        <span style="color: #800000;">&quot;'$commandText'&quot;</span>;
    <span style="color: #800080;">$sqlCommand</span>.ExecuteNonQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #800080;">$sqlConn</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$client</span>.Disconnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>And now you have a table filled with queries that will be cancelled (read: "error out") when the query killing job is running.  So now you fix it:</p>
<ol>
<li>locate these users</li>
<li>figure out what crazy pivots are causing the problem</li>
<li>Refactor the pivot OR determine what dimensionality is missing from the cube</li>
</ol>
<p>Once you go a day or so w/ a quiet log table, you can turn on the query killer and go on your merry way.  It's been suggested that we should send the user an email - let them know that it wasn't an error... that we cancelled their query.  Maybe - but honestly, you should probably email or call them personally to hash it out.  If it happens once, chalk it up to happenstance.  If it continues to occur, it's time for some user training and/or requirements gathering.</p>
<p>The real problem is that most end users don't know that 30 seconds is ridiculously long - they shouldn't have to wait that long.  Not only does it hurt them, it hurts others using the system as well.</p>
<p><em><strong>UPDATE:</strong>  You may want to, at some point, actually view one of these monster queries to see what on earth they were querying for.  Over a certain size, getting it out of SSMS can be pretty troublesome - A query similar to the following should do the trick:</em></p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">DECLARE @SQLcommand VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4000</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SET</span> @SQLcommand <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'bcp &quot;select CommandText 
from Database.dbo.LongRunningMDXQueryLog 
where SPID = 511519&quot; 
queryout &quot;c:<span style="color: #000099; font-weight: bold;">\o</span>utput.dtsx&quot; -T -c'</span>
&nbsp;
EXEC xp_cmdshell @SQLcommand</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2011/04/dealing-with-long-running-ssas-queries-using-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Analysis Services Writeback &#8211; Working with Weight Expressions</title>
		<link>http://timlaqua.com/2010/11/analysis-services-writeback-working-with-weight-expressions/</link>
		<comments>http://timlaqua.com/2010/11/analysis-services-writeback-working-with-weight-expressions/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 17:57:21 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[analysis services]]></category>
		<category><![CDATA[excel 2010]]></category>
		<category><![CDATA[ssas]]></category>
		<category><![CDATA[weight expression]]></category>
		<category><![CDATA[writeback]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=405</guid>
		<description><![CDATA[While writeback has been around for a while, it didn't really get easy to do until Excel 2010 was released because wrapping a UI around it was cumbersome. Now that we have a simple writeback UI via the What-If analysis dialogs in Excel, it's pry worth poking around at how to get things to allocate [...]]]></description>
			<content:encoded><![CDATA[<p>While writeback has been around for a while, it didn't really get easy to do until Excel 2010 was released because wrapping a UI around it was cumbersome.  Now that we have a simple writeback UI via the What-If analysis dialogs in Excel, it's pry worth poking around at how to get things to allocate the way you want.</p>
<p>Here's our starting point in the Adventure Works cube (note, I commented out all the scope statements in the MDX script that distribute quarterly quotas/targets to months - in AW, quotas only exist in the data warehouse at the calendar quarter level):<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-Start.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-Start.png" alt="" title="Writeback-Start" width="245" height="180" class="alignnone size-full wp-image-415" /></a></p>
<p>Let's start with something simple - Equal Allocation:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-EvenDist.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-EvenDist.png" alt="" title="Writeback-EvenDist" width="247" height="182" class="alignnone size-full wp-image-407" /></a><br />
<span id="more-405"></span><br />
Now let's try to figure out this Weight Expression thing by throwing a 1 in there:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne-178x300.png" alt="" title="Writeback-WeightExpressionOne" width="178" height="300" class="alignnone size-medium wp-image-417" /></a></p>
<p>Now discard previous changes and enter the quota at the Semester level again:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne-LeafCount.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne-LeafCount.png" alt="" title="Writeback-WeightExpressionOne-LeafCount" width="246" height="181" class="alignnone size-full wp-image-420" /></a></p>
<p>Ok, that wasn't what we intended - but it does kind of explain what it's up to.  That's the number of detail cells (leaves) that it wrote data to - and it wrote the entire quota amount to each cell, then added them all up.  Note that the first leaf got the true-up balance - if your custom aggregation doesn't roll up properly, it seems that it figures out how much you were off and tosses whatever number is required to make it aggregate right in to the first leaf.</p>
<p>Now to get the right weight expression, we have to divide 1 (the entire quota) by the number of leaves that it's writing data to.  Sales quotas are related to the Date dimension, the Sales Territory dimension, and the Employee dimension, so it's going to write out one value for every intersection of the leaves of those dimensions (at whichever level the measure group is related to the dimension, so it doesn't write out a value for every date, it writes out a value for every quarter - because that's the level that quotas are associated with the date dimension, calendar quarter).  So we basically want:</p>
<p><strong>1 / [number of employees] / [number of sales regions] / [number of quarters]</strong></p>
<p>Here's the weight expression to accomplish that (note that we assume that we know what we're trying to do here:  enter quotas at the fiscal semester level.  That's why the following expression gets the Semester ancestor of the current fiscal calendar member, because we know that we want to distribute evenly across all quarters and we entered data at the semester level)</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[All]</span>
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
 <span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory Region]</span>.<span style="color: #333333;">[All]</span>
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory Region]</span>.<span style="color: #333333;">[Sales Territory Region]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
 <span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #AF0000;">Ancestor</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #AF0000;">CurrentMember</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Semester]</span>
		 <span style="color: #003300; font-weight: bold;">&#41;</span>
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Quarter]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #003300; font-weight: bold;">&#41;</span></pre></div></div>

<p>And, of course, we end up with our old friend Equal Allocation:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne-Descendants-Results.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-WeightExpressionOne-Descendants-Results.png" alt="" title="Writeback-WeightExpressionOne-Descendants-Results" width="245" height="179" class="alignnone size-full wp-image-419" /></a></p>
<p>Now say you wanted to enter quotas at the intersection of the Fiscal Year and the Country.  Now we don't want all the sales regions anymore, we just want the Descendants of the current sales region's Ancestor at the Country level:</p>
<p>We start here:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-FiscalYear-SalesTerritory-Start.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-FiscalYear-SalesTerritory-Start.png" alt="" title="Writeback-FiscalYear-SalesTerritory-Start" width="348" height="261" class="alignnone size-full wp-image-409" /></a></p>
<p>And enter the following Weight Expression:</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #cc66cc;">1</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[All]</span>
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
 <span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #AF0000;">Ancestor</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory]</span>.<span style="color: #AF0000;">CurrentMember</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Country]</span>
		 <span style="color: #003300; font-weight: bold;">&#41;</span> 
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Region]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
 <span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
	<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		 <span style="color: #AF0000;">Ancestor</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #AF0000;">CurrentMember</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Year]</span>
		 <span style="color: #003300; font-weight: bold;">&#41;</span>
		<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Quarter]</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #003300; font-weight: bold;">&#41;</span></pre></div></div>

<p>And then we enter the quota at the intersection of Fiscal Semester and Country:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-FiscalYear-SalesTerritory-Even.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-FiscalYear-SalesTerritory-Even-300x153.png" alt="" title="Writeback-FiscalYear-SalesTerritory-Even" width="300" height="153" class="alignnone size-medium wp-image-408" /></a></p>
<p>So all we've done this far is reproduce numbers similar to what Equal Allocation would get us.  But what did we just do really?  We distributed the sales quotas across all employees - but only Sales People have sales quotas...  oops (the following is sliced by [Employee].[Sales Person Flag] on columns):<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-SalesPerson-Oops.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-SalesPerson-Oops-300x104.png" alt="" title="Writeback-SalesPerson-Oops" width="300" height="104" class="alignnone size-medium wp-image-412" /></a></p>
<p>And now we finally get to why we want to use Weight Expressions in the first place.  We only want to distribute quotas across sales people (note that we've went back to just distributing evenly across all sales regions again for simplicity):</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #CC00FF;">iif</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #AF0000;">CurrentMember</span>.<span style="color: #FF00FF;">Properties</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;Sales Person Flag&quot;</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;True&quot;</span>
<span style="color: #66cc66;">,</span>
	<span style="color: #cc66cc;">1</span>
	<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[All]</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Employee]</span>
		<span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #333333;">[Employee]</span>.<span style="color: #333333;">[Sales Person Flag]</span>.&amp;<span style="color: #333333;">[True]</span>
	 <span style="color: #003300; font-weight: bold;">&#41;</span>
	<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory Region]</span>.<span style="color: #333333;">[All]</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Sales Territory]</span>.<span style="color: #333333;">[Sales Territory Region]</span>.<span style="color: #333333;">[Sales Territory Region]</span>
		<span style="color: #003300; font-weight: bold;">&#41;</span>
	 <span style="color: #003300; font-weight: bold;">&#41;</span>
	<span style="color: #66cc66;">/</span><span style="color: #CC00FF;">Count</span><span style="color: #003300; font-weight: bold;">&#40;</span>
		<span style="color: #0000FF;">Descendants</span><span style="color: #003300; font-weight: bold;">&#40;</span>
			 <span style="color: #AF0000;">Ancestor</span><span style="color: #003300; font-weight: bold;">&#40;</span>
				 <span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #AF0000;">CurrentMember</span>
				<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Semester]</span>
			 <span style="color: #003300; font-weight: bold;">&#41;</span>
			<span style="color: #66cc66;">,</span><span style="color: #333333;">[Date]</span>.<span style="color: #333333;">[Fiscal]</span>.<span style="color: #333333;">[Fiscal Quarter]</span>
		<span style="color: #003300; font-weight: bold;">&#41;</span>
	<span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #66cc66;">,</span>Null<span style="color: #003300; font-weight: bold;">&#41;</span></pre></div></div>

<p>And the results:<br />
<a href="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-SalesPerson-Correct.png"><img src="http://timlaqua.com/wp-content/uploads/2010/11/Writeback-SalesPerson-Correct-300x108.png" alt="" title="Writeback-SalesPerson-Correct" width="300" height="108" class="alignnone size-medium wp-image-411" /></a></p>
<p>Great, we got that particular slice all fixed up - but what about if we slice by employee?  Did we distribute sales quotas for the US across sales people that don't even work in the US?  What-If analysis is just that - "what happens if I do this?"  If you're never going to look at more detailed slices, it's fine the way it is.  If you're using writeback to publish data to the cube and let others slice on it all willy-nilly, you need to examine all the slices you just wrote data to and make sure your weight expression allocates the data the way you intended it to.</p>
<p>In the end, do we expect business users to be able to write their own weight expressions, publish to the masses, and understand what exactly just happened?  I doubt it.  That's a bit much to ask.  We can, however, create accurate weight expressions for business users if we know exactly where they want to enter the new data.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2010/11/analysis-services-writeback-working-with-weight-expressions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>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>21</slash:comments>
		</item>
		<item>
		<title>Scrolling to and Highlighting Anchor Target via JavaScript</title>
		<link>http://timlaqua.com/2009/03/scrolling-to-and-highlighting-anchor-target-via-javascript/</link>
		<comments>http://timlaqua.com/2009/03/scrolling-to-and-highlighting-anchor-target-via-javascript/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 02:11:59 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[cube action]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[parse anchor]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=147</guid>
		<description><![CDATA[I implemented a SSAS cube action to link to a SharePoint page (URL Action) with the name of the measure contained in the cell the user fired the action from. The theory here is to have a page that contains a list of definitions for all measures (both real and calculated) in the cube. As [...]]]></description>
			<content:encoded><![CDATA[<p>I implemented a SSAS cube action to link to a SharePoint page (URL Action) with the name of the measure contained in the cell the user fired the action from.  The theory here is to have a page that contains a list of definitions for all measures (both real and calculated) in the cube.  As we were flushing out this implementation, it was suggested that the page should scroll to the specified measure and highlight it in some way.  The implementation of this using the CSS :target pseudo class is pretty straightforward - however we're a Microsoft shop and we absolutely have to support Internet Explorer 7 and Internet Explorer 8, so that's out.<br />
<span id="more-147"></span><br />
Originally, the plan was to use Anchor Targets, but since the implementation ended up being pure JavaScript, there really was no reason to use anchors - we used something like this to define measures:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dataDictionary&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;termNotFound&quot;</span>&gt;</span>Specified definition could not be found.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Term goes here<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Definition goes here<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Additional Comments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>comment<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Other Term goes here<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Other Definition goes here<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Additional Comments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>comment<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>And the following JavaScript is used to locate the appropriate heading, modify it's parent DIV (to add the selected className so it gets different styling), and scroll down to it:</p>
<p>ParseURI function from <a href="http://blog.stevenlevithan.com/archives/parseuri">http://blog.stevenlevithan.com/archives/parseuri</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> parseUri <span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span>	o   <span style="color: #339933;">=</span> parseUri.<span style="color: #660066;">options</span><span style="color: #339933;">,</span>
		m   <span style="color: #339933;">=</span> o.<span style="color: #660066;">parser</span><span style="color: #009900;">&#91;</span>o.<span style="color: #660066;">strictMode</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;strict&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;loose&quot;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		uri <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		i   <span style="color: #339933;">=</span> <span style="color: #CC0000;">14</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> uri<span style="color: #009900;">&#91;</span>o.<span style="color: #660066;">key</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> m<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	uri<span style="color: #009900;">&#91;</span>o.<span style="color: #660066;">q</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	uri<span style="color: #009900;">&#91;</span>o.<span style="color: #660066;">key</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">12</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">q</span>.<span style="color: #660066;">parser</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>$<span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> $<span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> $<span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> uri<span style="color: #009900;">&#91;</span>o.<span style="color: #660066;">q</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>$<span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> uri<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
parseUri.<span style="color: #660066;">options</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	strictMode<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	key<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;source&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;protocol&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;authority&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;userInfo&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;user&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;host&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;port&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;path&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;directory&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;file&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;query&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;anchor&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	q<span style="color: #339933;">:</span>   <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">name</span><span style="color: #339933;">:</span>   <span style="color: #3366CC;">&quot;queryKey&quot;</span><span style="color: #339933;">,</span>
		parser<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/(?:^|&amp;)([^&amp;=]*)=?([^&amp;]*)/g</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	parser<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		strict<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/</span><span style="color: #339933;">,</span>
		loose<span style="color: #339933;">:</span>  <span style="color: #009966; font-style: italic;">/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ScrollToElement function from <a href="http://radio.javaranch.com/pascarello/2005/01/09/1105293729000.html">http://radio.javaranch.com/pascarello/2005/01/09/1105293729000.html</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> ScrollToElement<span style="color: #009900;">&#40;</span>theElement<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> selectedPosX <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> selectedPosY <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>theElement <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    selectedPosX <span style="color: #339933;">+=</span> theElement.<span style="color: #660066;">offsetLeft</span><span style="color: #339933;">;</span>
    selectedPosY <span style="color: #339933;">+=</span> theElement.<span style="color: #660066;">offsetTop</span><span style="color: #339933;">;</span>
    theElement <span style="color: #339933;">=</span> theElement.<span style="color: #660066;">offsetParent</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
 window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span>selectedPosX<span style="color: #339933;">,</span>selectedPosY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Some quick string manipulation functions form <a href="http://www.webtoolkit.info/javascript-trim.html">http://www.webtoolkit.info/javascript-trim.html</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> trim<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> chars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> ltrim<span style="color: #009900;">&#40;</span>rtrim<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> chars<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> chars<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ltrim<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> chars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	chars <span style="color: #339933;">=</span> chars <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;^[&quot;</span> <span style="color: #339933;">+</span> chars <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;]+&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> rtrim<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> chars<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	chars <span style="color: #339933;">=</span> chars <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>s&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;[&quot;</span> <span style="color: #339933;">+</span> chars <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;]+$&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And finally, some original code to make it all work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> hotlink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> colP <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> colP.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>colP.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			colP<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> colP<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(&quot;</span> <span style="color: #339933;">+</span> ddTerms <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;^$)&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>javascript:findTerm('$1')<span style="color: #000099; font-weight: bold;">\&quot;</span>'&gt;$1&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> findTerm<span style="color: #009900;">&#40;</span>term<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> colDIV <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> colDIV.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>colDIV.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">%</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				colDIV<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'alt'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				className <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> colH1 <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'h1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> colH1.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>colH1.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> ddTerm <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>colH1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ddTerm <span style="color: #339933;">==</span> term.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
				colH1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'selected'</span><span style="color: #339933;">;</span>
				ScrollToElement<span style="color: #009900;">&#40;</span>colH1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			ddTerms <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>b&quot;</span> <span style="color: #339933;">+</span> ddTerm.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(<span style="color: #000099; font-weight: bold;">\\</span>(|<span style="color: #000099; font-weight: bold;">\\</span>))&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;g&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>$1&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>b|&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>found <span style="color: #339933;">&amp;&amp;</span> term.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> tnf <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'termNotFound'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			tnf.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
			ScrollToElement<span style="color: #009900;">&#40;</span>tnf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> ddTerms <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	findTerm<span style="color: #009900;">&#40;</span>unescape<span style="color: #009900;">&#40;</span>parseUri<span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">anchor</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	hotlink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note, there's also a hotlink() function in there - since this is a page full of terms and definitions, we might as well link up the page so all terms are clickable within the document.</p>
<p>Finally, make it looke somewhat presentable with either an inline style block or just add these to your external style sheet:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">	<span style="color: #cc00cc;">#dataDictionary</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#dataDictionary</span> 
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">110</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccccff</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div p
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div ul
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#termNotFound</span> 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">dotted</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffff77</span> !important<span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div h1 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">130</span>%</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccbbff</span><span style="color: #00AA00;">;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#dataDictionary</span> div h2 <span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">115</span>%</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">0pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div ul 
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2pt</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div<span style="color: #6666ff;">.alt</span>  h1
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#88ff88</span><span style="color: #00AA00;">;</span> 
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#dataDictionary</span> div.alt 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#bbffaa</span><span style="color: #00AA00;">;</span> 
	<span style="color: #00AA00;">&#125;</span>	
&nbsp;
	<span style="color: #cc00cc;">#dataDictionary</span> div<span style="color: #6666ff;">.selected</span> h1 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff7755</span><span style="color: #00AA00;">;</span> 
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#dataDictionary</span> div.selected 
	<span style="color: #00AA00;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ff9988</span><span style="color: #00AA00;">;</span> 
		<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">125</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2009/03/scrolling-to-and-highlighting-anchor-target-via-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wierd Slice &#8211; Revenue for the Most Recent Hour in the Cube Across the Last 14 Days Sliced by Week</title>
		<link>http://timlaqua.com/2009/02/wierd-slice-revenue-for-the-most-recent-hour-in-the-cube-across-the-last-seven-days/</link>
		<comments>http://timlaqua.com/2009/02/wierd-slice-revenue-for-the-most-recent-hour-in-the-cube-across-the-last-seven-days/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 01:12:35 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[calculated measure]]></category>
		<category><![CDATA[calculated member]]></category>
		<category><![CDATA[cube]]></category>
		<category><![CDATA[mdx]]></category>
		<category><![CDATA[recent hour]]></category>
		<category><![CDATA[ssas]]></category>
		<category><![CDATA[subcube]]></category>
		<category><![CDATA[tail]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=64</guid>
		<description><![CDATA[Well - there's two parts to this - one is to figure out the most recent hour in the cube that has data. Let's face it, it finishes as soon as it can - but that time may vary now and then. Then, for this particular report, we wanted to see the last seven days [...]]]></description>
			<content:encoded><![CDATA[<p>Well - there's two parts to this - one is to figure out the most recent hour in the cube that has data.  Let's face it, it finishes as soon as it can - but that time may vary now and then.  Then, for this particular report, we wanted to see the last seven days on one series and the previous seven days on another series.  To do this, we just slice by two calculated measures.  But this creates an odd dateset where the This Week column will have no data for the "Date Time" columns that actually belong to the Previous Week.</p>
<p>This isn't really a problem as in SSRS, you can simply define the Category Group for the Series in your chart (ya, I didn't mention that yet - this is all for a chart) as DatePart("w", Fields!DateTime) - which will group everything by the number of the given weekday and then you can just have your "This Week" and "Prevoius Week" series.</p>

<div class="wp_syntax"><div class="code"><pre class="mdx" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">WITH</span> 
  <span style="color: #0000FF; font-weight: bold;">MEMBER</span> <span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[This Week]</span> <span style="color: #0000FF; font-weight: bold;">AS</span> 
    <span style="color: #CC00FF;">Aggregate</span>
    <span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span><span style="color: #66cc66;">:</span><span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span>.<span style="color: #AF0000;">Lag</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #003300; font-weight: bold;">&#41;</span>
     <span style="color: #66cc66;">,</span><span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[Revenue]</span><span style="color: #003300; font-weight: bold;">&#41;</span>
&nbsp;
  <span style="color: #0000FF; font-weight: bold;">MEMBER</span> <span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[Previous Week]</span> <span style="color: #0000FF; font-weight: bold;">AS</span> 
     <span style="color: #CC00FF;">Aggregate</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span>.<span style="color: #AF0000;">Lag</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #003300; font-weight: bold;">&#41;</span>
     <span style="color: #66cc66;">:</span>
     <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span>.<span style="color: #AF0000;">Lag</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #003300; font-weight: bold;">&#41;</span>
     <span style="color: #66cc66;">,</span><span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[Revenue]</span><span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">SELECT</span> 
  <span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> 
    <span style="color: #003300; font-weight: bold;">&#123;</span><span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[Previous Week]</span><span style="color: #66cc66;">,</span> <span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[This Week]</span><span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span>
 <span style="color: #66cc66;">,</span><span style="color: #0000FF; font-weight: bold;">NON</span> <span style="color: #0000FF; font-weight: bold;">EMPTY</span> 
    <span style="color: #003300; font-weight: bold;">&#123;</span> 
        <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Date Time]</span>.<span style="color: #333333;">[Date Time]</span>.<span style="color: #0000FF;">MEMBERS</span> 
        <span style="color: #66cc66;">*</span> 
        <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[24 Hour]</span>.<span style="color: #333333;">[24 Hour]</span>.<span style="color: #0000FF;">ALLMEMBERS</span>
    <span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">1</span>
<span style="color: #0000FF; font-weight: bold;">FROM</span> 
<span style="color: #003300; font-weight: bold;">&#40;</span>
  <span style="color: #0000FF; font-weight: bold;">SELECT</span> 
    <span style="color: #0000FF;">Tail</span><span style="color: #003300; font-weight: bold;">&#40;</span>
         <span style="color: #0000FF;">Filter</span><span style="color: #003300; font-weight: bold;">&#40;</span>
               <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[24 Hour]</span>.<span style="color: #333333;">[24 Hour]</span>.<span style="color: #0000FF;">MEMBERS</span>
               <span style="color: #66cc66;">,</span><span style="color: #CC00FF;">Sum</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span><span style="color: #66cc66;">,</span><span style="color: #333333;">[Measures]</span>.<span style="color: #333333;">[Revenue]</span><span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span>
         <span style="color: #003300; font-weight: bold;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span>
    <span style="color: #003300; font-weight: bold;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span>
  <span style="color: #0000FF; font-weight: bold;">FROM</span> 
  <span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #0000FF; font-weight: bold;">SELECT</span> 
      <span style="color: #003300; font-weight: bold;">&#123;</span>
            <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span>
            <span style="color: #66cc66;">:</span>
            <span style="color: #333333;">[Time]</span>.<span style="color: #333333;">[Calendar Date]</span>.<span style="color: #AF0000;">LastChild</span>.<span style="color: #AF0000;">Lag</span><span style="color: #003300; font-weight: bold;">&#40;</span><span style="color: #cc66cc;">13</span><span style="color: #003300; font-weight: bold;">&#41;</span>
      <span style="color: #003300; font-weight: bold;">&#125;</span> <span style="color: #0000FF; font-weight: bold;">ON</span> <span style="color: #cc66cc;">0</span>
    <span style="color: #0000FF; font-weight: bold;">FROM</span> <span style="color: #333333;">[Cube]</span>
  <span style="color: #003300; font-weight: bold;">&#41;</span>
<span style="color: #003300; font-weight: bold;">&#41;</span></pre></div></div>

<p>And to top it all off - after seeing the chart for a while, nobody liked it (after all, it's a relatively abstract view of revenue) and we dumped it.  <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/02/wierd-slice-revenue-for-the-most-recent-hour-in-the-cube-across-the-last-seven-days/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add a calculated measure (calculated field) to an Excel 2007 PivotTable with a SSAS data source</title>
		<link>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/</link>
		<comments>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 18:28:12 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[How-to Guides]]></category>
		<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[calculated measure]]></category>
		<category><![CDATA[calculated member]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[named set]]></category>
		<category><![CDATA[pivottable]]></category>
		<category><![CDATA[ssas]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=50</guid>
		<description><![CDATA[As it turns out, you can do it programatically as explained by Allan Folting here: Microsoft Excel: Common Questions Around Excel 2007 OLAP PivotTables: http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx And the parts that I have to keep looking up (I use my blog as a notebook for things I don't want to forget : Sub AddCalculatedMeasure() Dim pvt As [...]]]></description>
			<content:encoded><![CDATA[<p>As it turns out, you can do it programatically as explained by <strong>Allan Folting </strong>here:<br />
<strong>Microsoft Excel: Common Questions Around Excel 2007 OLAP PivotTables</strong>:<br />
<a href="http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx">http://blogs.msdn.com/excel/archive/2008/02/05/common-questions-around-excel-2007-OLAP-PivotTables.aspx</a></p>
<p>And the parts that I have to keep looking up (I use my blog as a notebook for things I don't want to forget <img src='http://timlaqua.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> :</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Sub</span> AddCalculatedMeasure() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[Measures].[Internet Sales Amount 25 %]&quot;
	strFormula = &quot;[Measures].[Internet Sales Amount]*1.25&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedMember 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span> 
&nbsp;
<span style="color: #000080;">Sub</span> AddCalculatedMember() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38 25 %]&quot;
	strFormula = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].[Mountain-100 Silver, 38]*1.25&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedMember
	pvt.ViewCalculatedMembers = <span style="color: #000080;">True</span> 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span> 
&nbsp;
<span style="color: #000080;">Sub</span> AddNamedSet() 
	<span style="color: #000080;">Dim</span> pvt <span style="color: #000080;">As</span> PivotTable
	<span style="color: #000080;">Dim</span> strName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> strFormula <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
	<span style="color: #000080;">Dim</span> cbf <span style="color: #000080;">As</span> CubeField 
&nbsp;
	<span style="color: #000080;">Set</span> pvt = Sheet1.PivotTables(&quot;PivotTable1&quot;)
	strName = &quot;[My Mountain Bikes]&quot;
	strFormula = &quot;[Product].[Product Categories].[Bikes].[Mountain Bikes].children&quot;
	pvt.CalculatedMembers.Add Name:=strName, Formula:=strFormula, <span style="color: #000080;">Type</span>:=xlCalculatedSet
	<span style="color: #000080;">Set</span> cbf = pvt.CubeFields.AddSet(Name:=&quot;[My Mountain Bikes]&quot;, Caption:=&quot;Mountain Bikes&quot;) 
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>He also mentions that you can expose these members to Excel Services 2007 by creating the new objects and then removing the VBA code - very useful article.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/11/how-to-add-a-calculated-measure-calculated-field-to-an-excel-2007-pivottable-with-a-ssas-data-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Server Names in Excel 2007 Embedded Workbook Connections</title>
		<link>http://timlaqua.com/2008/09/changing-server-names-in-excel-2007-embeded-workbook-connections/</link>
		<comments>http://timlaqua.com/2008/09/changing-server-names-in-excel-2007-embeded-workbook-connections/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 19:59:44 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Scripts & Code]]></category>
		<category><![CDATA[connections]]></category>
		<category><![CDATA[data sources]]></category>
		<category><![CDATA[embeded connections]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[excel 2007]]></category>
		<category><![CDATA[pivot table]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[ssas]]></category>
		<category><![CDATA[vbscript]]></category>

		<guid isPermaLink="false">http://timlaqua.com/?p=48</guid>
		<description><![CDATA[Ok, so you want to migrate servers, eh? Well - all your business users pry have a couple thousand Pivot Reports lying around that point to the old server. We need to point all references to the old server at the new server. There are two places these references exist (afaik) - The My Data [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so you want to migrate servers, eh?  Well - all your business users pry have a couple thousand Pivot Reports lying around that point to the old server.  We need to point all references to the old server at the new server.</p>
<p>There are two places these references exist (afaik) - The My Data Sources folder (Windows XP / Excel 2007) which holds all of the odc objects for the logged in user, and the real pain - Embedded data sources in Excel Workbooks.</p>
<p>For the odc objects - you can just loop through the My Data Sources folder files and do a little find/replace action.</p>
<p>For the Excel files - we need to first find all the files, then loop through them and hunt for embedded Connections.  Once we find a connection, we can just blindly replace occurrences of the old server name with the new server name.  The first thing we need here is a function we can call recursively to go hunt down all the excel files - then we loop through and play with the connections (when found).<br />
<span id="more-48"></span></p>
<p>Let me know how it goes!  Here's the full version:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Set</span> regEx = <span style="color: #000080;">New</span> RegExp
regEx.IgnoreCase = <span style="color: #000080;">True</span>
regEx.Global = <span style="color: #000080;">True</span>
<span style="color: #000080;">Set</span> WshShell = Wscript.CreateObject(&quot;Wscript.Shell&quot;)
strMyDocsPath = WshShell.RegRead(&quot;HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal&quot;)
strDataSourceDir = strMyDocsPath &amp; &quot;\My Data Sources&quot;
&nbsp;
<span style="color: #008000;">'======================== Fix all the Data Sources
</span><span style="color: #000080;">Set</span> objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
<span style="color: #000080;">Set</span> Folder = objFSO.GetFolder(strDataSourceDir)
<span style="color: #000080;">Set</span> Files = Folder.Files
&nbsp;
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> File <span style="color: #000080;">In</span> Files
	<span style="color: #000080;">If</span> LCase(Right(File.Name, 4)) = &quot;.odc&quot; <span style="color: #000080;">Then</span>
	    <span style="color: #000080;">Set</span> objReadFile = objFSO.OpenTextFile(File.Path, 1)
	    strContents = &quot;&quot;
&nbsp;
		<span style="color: #000080;">Do</span> <span style="color: #000080;">While</span> <span style="color: #000080;">Not</span> objReadFile.AtEndOfStream
			strContents = strContents &amp; objReadFile.ReadLine &amp; vbCrLf
		<span style="color: #000080;">Loop</span>
&nbsp;
	    objReadFile.<span style="color: #000080;">Close</span>
&nbsp;
		regEx.Pattern = &quot;(?=.*Data Source=OldCrappyServerName.*)(&lt;odc:ConnectionString&gt;.+&lt;/odc:ConnectionString&gt;)&quot;
&nbsp;
		<span style="color: #000080;">If</span> regEx.Test(strContents) <span style="color: #000080;">Then</span>
			<span style="color: #000080;">Set</span> colMatches = regEx.Execute(strContents)
&nbsp;
			<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objMatch <span style="color: #000080;">in</span> colMatches
				strOldConnectionString = objMatch.SubMatches(0)
				regEx.Pattern = &quot;Data Source=OldCrappyServerName&quot;
				strNewConnectionString = regEx.Replace(strOldConnectionString, &quot;Data Source=NewAwesomeServerName&quot;)
				regEx.Pattern = strOldConnectionString
				strContents = regEx.Replace(strContents, strNewConnectionString)
			<span style="color: #000080;">Next</span>
&nbsp;
			<span style="color: #000080;">Set</span> objWriteFile = objFSO.CreateTextFile(File.Path, <span style="color: #000080;">True</span>)
			objWriteFile.Write strContents
			objWriteFile.<span style="color: #000080;">Close</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">Next</span>
&nbsp;
&nbsp;
<span style="color: #008000;">'================================ Fix all the embeded connections (yikes)
</span>
<span style="color: #000080;">Set</span> arrFileList = CreateObject( &quot;System.Collections.ArrayList&quot; )
<span style="color: #000080;">Set</span> objExcel = CreateObject(&quot;Excel.Application&quot;)
objExcel.DisplayAlerts = <span style="color: #000080;">False</span>
&nbsp;
populateExcelFileList(strMyDocsPath)
&nbsp;
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> strFileName <span style="color: #000080;">In</span> arrFileList
	objExcel.Workbooks.<span style="color: #000080;">Open</span>(strFileName)
	<span style="color: #000080;">Set</span> objWorkbook = objExcel.Workbooks(1)
	<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objWorkbook <span style="color: #000080;">in</span> objExcel.Workbooks
		<span style="color: #000080;">If</span> objWorkbook.Connections.Count &gt; 0 <span style="color: #000080;">Then</span>
			WScript.Echo strFileName
			<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> objConnection <span style="color: #000080;">in</span> objWorkbook.Connections
				strOldConnection =  objConnection.OLEDBConnection.Connection
				regEx.Pattern = &quot;OldCrappyServerName&quot;
				strNewConnection = regEx.Replace(strOldConnection, &quot;NewAwesomeServerName&quot;)
				objConnection.OLEDBConnection.Connection = strNewConnection
			<span style="color: #000080;">Next</span>
&nbsp;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		objWorkbook.<span style="color: #000080;">Close</span> <span style="color: #000080;">True</span>
	<span style="color: #000080;">Next</span>
&nbsp;
	objExcel.Quit
<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">Function</span> populateExcelFileList(path)
	<span style="color: #000080;">Set</span> pathFolder = objFSO.GetFolder(path)
	<span style="color: #000080;">Set</span> pathFiles = pathFolder.Files
	<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> pathSubFolder <span style="color: #000080;">in</span> pathFolder.SubFolders
		populateExcelFileList(pathSubFolder.Path)
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> pathFile <span style="color: #000080;">in</span> pathFiles
		<span style="color: #000080;">If</span> (LCase(Right(pathFile.Name, 5)) = &quot;.xlsx&quot; _
			<span style="color: #000080;">Or</span> LCase(Right(pathFile.Name, 4)) = &quot;.xls&quot;) _
			<span style="color: #000080;">And</span> Left(pathFile.Name, 1) &lt;&gt; &quot;~&quot; <span style="color: #000080;">Then</span>
			arrFileList.Add pathFile.Path
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></td></tr></table></div>

<p><strong><em>Update</em></strong><br />
I added in support for .xls files - doing this against .xls files can (and usually will) break backwards compatibility for SSAS Pivot Tables.</p>
]]></content:encoded>
			<wfw:commentRss>http://timlaqua.com/2008/09/changing-server-names-in-excel-2007-embeded-workbook-connections/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

