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

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

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

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

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