<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Kasper de Jonge PowerPivot BlogKasper de Jonge PowerPivot Blog</title>
	
	<link>http://www.powerpivotblog.nl</link>
	<description>Bringing BI to the masses</description>
	<lastBuildDate>Wed, 01 May 2013 15:58:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kjonge" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="kjonge" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Help, I received a pivoted data file that I want to combine with my data in PowerPivot</title>
		<link>http://www.powerpivotblog.nl/help-i-received-a-pivoted-data-file-that-i-want-to-combine-with-my-data-in-powerpivot</link>
		<comments>http://www.powerpivotblog.nl/help-i-received-a-pivoted-data-file-that-i-want-to-combine-with-my-data-in-powerpivot#comments</comments>
		<pubDate>Wed, 01 May 2013 03:48:11 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2969</guid>
		<description><![CDATA[Often when working in Excel you get all kinds of flattened files that come from all kinds of different source and you want to use as them as a source for your analysis. Today we are looking at how DataExplorer can help you with this. Click here to download DataExplorer, for more details on Data Explorer check [...]]]></description>
				<content:encoded><![CDATA[<p>Often when working in Excel you get all kinds of flattened files that come from all kinds of different source and you want to use as them as a source for your analysis. Today we are looking at how DataExplorer can help you with this. Click <a href="http://www.microsoft.com/en-us/download/details.aspx?id=36803">here </a>to download DataExplorer, for more details on Data Explorer check out my previous blogs.</p>
<p>Image we have the following Products with revenue for the following fiscal year and month. This data comes from your nicely structured datawarehouse:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image14.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb14.png" width="373" height="405" border="0" /></a></p>
<p>Your managers, who asked for this report, wants to see these values combined with the target values. You get these values delivered in the following pivoted text file:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image15.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb15.png" width="698" height="383" border="0" /></a></p>
<p>The problem with a format like this is that it is not easy to pivot on. In order for us to to do analytics on top of this we need to reshape the data into a shape where the months and years become a value, not a header. This is called Unpivotting.</p>
<p>So how do I do this ? And how do you get these numbers into one combined  Pivottable ? The answer here is Data Explorer. I select import from CSV in DataExplorer and point to the CSV file.</p>
<p>First I double click on Query and rename the query to revenueTarget to give the query a proper name, next I select that I want the First row as headers:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image16.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb16.png" width="728" height="402" border="0" /></a></p>
<p>select all the columns that contain values and right mouse click, select Unpivot columns:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image17.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb17.png" width="739" height="405" border="0" /></a></p>
<p>This will give us the result we want where year and month have now become values instead of column headers:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image18.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb18.png" width="443" height="450" border="0" /></a></p>
<p>Now I rename columns to something sensible. In my PowerPivot model I need to combine this data with a date column so I would like to add that as well. I right mouse click on the date column, press Insert Column and select Custom</p>
<p>Here I can enter a value that will create a new date field:</p>
<p>=Text.End([YearMonth],2) &amp; &#8220;/1/&#8221; &amp;Text.Start([YearMonth],4)</p>
<p>And I Change the type to Date:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image19.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb19.png" width="739" height="412" border="0" /></a></p>
<p>Ok the transformations are completed. Press Done and Add the results to the data model:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image20.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb20.png" width="589" height="555" border="0" /></a></p>
<p>Now to add this to the data model I need d to create relationships, I do this by creating relationships to the DateTable and Product. I am essentially treating this new table a secondary fact table:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image21.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb21.png" width="682" height="391" border="0" /></a></p>
<p>Now to combine values from the Invoice table and RevenueTarget into one KPI I go back to the datagrid view, select the RevenueTarget column and click autosum on the ribbon to create a measure for Sum of RevenueTarget. I also create a measure for that will serve as the base measure for our KPI. I add the following measure:</p>
<p>KPI:=[Sum of RevenueAmount]</p>
<p>Now I right mouse click and select KPI, I select the Sum of RevenueTarget as target value:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image22.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb22.png" width="566" height="470" border="0" /></a></p>
<p>Now adding this KPI to the Pivottable we had in the beginning and voila:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image23.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb23.png" width="499" height="403" border="0" /></a></p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/2l3Az9Q1ZI8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/help-i-received-a-pivoted-data-file-that-i-want-to-combine-with-my-data-in-powerpivot/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When Importing from Tabular Model use DAX</title>
		<link>http://www.powerpivotblog.nl/when-importing-from-tabular-model-use-dax</link>
		<comments>http://www.powerpivotblog.nl/when-importing-from-tabular-model-use-dax#comments</comments>
		<pubDate>Thu, 25 Apr 2013 00:19:21 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2946</guid>
		<description><![CDATA[I recently was building a model in Excel that was using data from a Tabular Model. I started going down the import path by selecting import from Analysis Services in the PowerPivot window and use the MDX query designer to select the data that I want to import into PowerPivot / Excel Model. I imported [...]]]></description>
				<content:encoded><![CDATA[<p>I recently was building a model in Excel that was using data from a Tabular Model. I started going down the import path by selecting import from Analysis Services in the PowerPivot window and use the MDX query designer to select the data that I want to import into PowerPivot / Excel Model.</p>
<p>I imported the data but it took over one hour to import the data. I was very unsatisfied with the time it took me to refresh the data. Then I got thinking, MDX is not really designed for these tabular result sets, DAX is. As this is a tabular model I can use DAX to get the results. Unfortunately I don’t have a automated DAX query editor but writing the DAX equivalent of this particular MDX query is quite simple. After rewriting the query to DAX is brought back the import time to …. 3 minutes. From one hour on the same dataset.</p>
<p>These are the steps needed to import the data, to start you get this empty window that asks you to specify the MDX query:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image12.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb12.png" width="321" height="341" border="0" /></a></p>
<p>Now instead of writing the MDX you can click on Design to have the MDX query designer help you build it:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image13.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb13.png" width="423" height="299" border="0" /></a></p>
<p>Now press OK or click on the designer Icon in the top right to get to see the MDX. The query builder will generate the following MDX:</p>
<blockquote><p>SELECT NON EMPTY { [Measures].[Sum of SalesAmount] } ON COLUMNS,</p>
<p>NON EMPTY { ([DateTable].[FullDateAlternateKey].[FullDateAlternateKey].ALLMEMBERS *</p>
<p>[Product].[Color].[Color].ALLMEMBERS *</p>
<p>[Product].[ModelName].[ModelName].ALLMEMBERS ) }</p>
<p>DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS</p>
<p>FROM ( SELECT ( { [DateTable].[CalendarYear].&amp;[2004] } )</p>
<p>ON COLUMNS FROM [Model])</p>
<p>WHERE ( [DateTable].[CalendarYear].&amp;[2004] )</p>
<p>CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS</p></blockquote>
<p>Now rewriting this to DAX, interesting to note is that DAX works inside out, start by reading the comments/functions from the most inner function and work your way to the outside to see what the query returns:</p>
<blockquote><p>EVALUATE<br />
//Calculate the table to filter the results by the CalendarYear 2004<br />
CALCULATETABLE(<br />
//Add columns to table containing the measures<br />
ADDCOLUMNS(<br />
//Filter the results where we actualy have a measure<br />
FILTER(<br />
//Crossjoin all the columns required in the resultset<br />
CROSSJOIN(<br />
values(DateTable[FullDateAlternateKey]),<br />
//when multiple columns from same table add them together with<br />
//Summarize for performance<br />
Summarize(values(Product),<br />
Product[color],<br />
Product[ModelName])<br />
)<br />
, Not IsBlank(Sales[Sum of SalesAmount])<br />
)<br />
, &#8220;[Total]&#8220;, Sales[Sum of SalesAmount]<br />
)<br />
, DateTable[calendaryear] = 2004<br />
)</p></blockquote>
<p>The above query is also a general approach on how you should write a query to retrieve a tabular result set using DAX to get the fastest result. It should work in most circumstances.</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/v4fQb6PwhG4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/when-importing-from-tabular-model-use-dax/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analyze a Twitter feed with Excel 2013, DataExplorer and GeoFlow</title>
		<link>http://www.powerpivotblog.nl/analyze-a-twitter-feed-with-excel-2013-dataexplorer-and-geoflow</link>
		<comments>http://www.powerpivotblog.nl/analyze-a-twitter-feed-with-excel-2013-dataexplorer-and-geoflow#comments</comments>
		<pubDate>Thu, 18 Apr 2013 03:48:27 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Analysis services]]></category>
		<category><![CDATA[Data Explorer]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2935</guid>
		<description><![CDATA[I recently got access to a csv file that contains twitter feeds filtered by Azure. I want to do some simple analytics on where the twitter users live in a visual way. I am going to load the csv file into Excel using DataExplorer (download add-in for Excel 2012 here). And I select Import from [...]]]></description>
				<content:encoded><![CDATA[<p>I recently got access to a csv file that contains twitter feeds filtered by Azure. I want to do some simple analytics on where the twitter users live in a visual way.</p>
<p>I am going to load the csv file into Excel using DataExplorer (download add-in for Excel 2012 <a href="http://www.microsoft.com/en-us/download/details.aspx?id=36803" target="_blank">here</a>).</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb.png" width="425" height="407" border="0" /></a></p>
<p>And I select Import from Csv, and select the file that I received. That opens the DataExplorer query editor and in this case I want to import the csv file completely without any changes. I do want to Use the first Row as Headers :</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb1.png" width="740" height="409" border="0" /></a></p>
<p>Now I import this data into Excel,</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb2.png" width="734" height="341" border="0" /></a></p>
<p>after importing the data into Excel I want to rename my query by double clicking Query1 and rename it to “Twitter Data” and press Load to data model to load it into the AS engine.</p>
<p>Now I want to plot the tweets on a map. I am going to use <a href="http://download-geoflow-for-excel-FX104036784" target="_blank">GeoFlow</a> for that, as this is data that I got from the Internet there are some data quality issues. The current version of GeoFlow doesn&#8217;t  allow us to filter data. So I am going to use a Excel trick to create a filtered down table by using a Query Table where I filter out all tweets where no region is defined.</p>
<p>So we go back to Excel, select an empty sheet and click on Data, Existing Connections, Tables and double click the Twitter data table:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image3.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb3.png" width="455" height="440" border="0" /></a></p>
<p>And press OK in the next dialog to add a table. This adds a table to the Excel sheet:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image4.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb4.png" width="714" height="436" border="0" /></a></p>
<p>Now right mouse click on the table and select Table, Edit DAX:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image5.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb5.png" width="430" height="297" border="0" /></a></p>
<p>Now I change what is shown on the sheet by editing the DAX expression for this table:</p>
<blockquote><p>Evaluate<br />
calculatetable(<br />
Summarize(<br />
&#8216;Twitter data&#8217;,<br />
&#8216;Twitter data&#8217;[ID]<br />
,&#8217;Twitter data&#8217;[Location]<br />
)<br />
, ISBLANK(&#8216;Twitter data&#8217;[Location]) = false)</p></blockquote>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image6.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb6.png" width="512" height="359" border="0" /></a></p>
<p>Press OK and this will only give me that ID’s and Locations where the Location is not blank:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image7.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb7.png" width="392" height="422" border="0" /></a></p>
<p><em>Comment: the results of the query will have the limitation of 1,000,000 rows in Excel but you could always aggregate the results by location using DAX. I don&#8217;t think many people want to plot more than a 1,000,000 locations. </em></p>
<p>Now go to Insert GeoFlow (Install add-in <a href="http://office.microsoft.com/en-us/download-geoflow-for-excel-FX104036784.aspx" target="_blank">here</a>):</p>
<p>In GeoFlow you now can pick columns from the filtered table:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image8.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb8.png" width="238" height="244" border="0" /></a></p>
<p>Now select location as other and Map it:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image9.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb9.png" width="217" height="285" border="0" /></a></p>
<p>Now select ID as height:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image10.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb10.png" width="225" height="244" border="0" /></a></p>
<p>This plots all the tweets on Azure for the last week on the map, you might notice the Netherlands and Belgium are quite some hotspots on Azure <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/wlEmoticon-smile.png" /> (no I did not rig the results!)</p>
<p>&nbsp;</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image11.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/04/image_thumb11.png" width="740" height="396" border="0" /></a></p>
<p>&nbsp;</p>
<p>Hope that you some idea’s on how to use Excel, DataExplorer and GeoFlow.</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/G3UBzFJqiIE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/analyze-a-twitter-feed-with-excel-2013-dataexplorer-and-geoflow/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated theme</title>
		<link>http://www.powerpivotblog.nl/updated-theme</link>
		<comments>http://www.powerpivotblog.nl/updated-theme#comments</comments>
		<pubDate>Tue, 09 Apr 2013 17:01:23 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2907</guid>
		<description><![CDATA[I updated the theme of my blog after 4 years. I like the clean looks of the style formerly known as metro. Let me know what you think or have any comments! Kasper]]></description>
				<content:encoded><![CDATA[<p>I updated the theme of my blog after 4 years. I like the clean looks of the style formerly known as metro. Let me know what you think or have any comments!</p>
<p>Kasper</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/pbccsYkW-yw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/updated-theme/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>NBA team spending and their results with Excel, PowerPivot and Data Explorer</title>
		<link>http://www.powerpivotblog.nl/nba-team-spending-and-their-results-with-excel-powerpivot-and-data-explorer</link>
		<comments>http://www.powerpivotblog.nl/nba-team-spending-and-their-results-with-excel-powerpivot-and-data-explorer#comments</comments>
		<pubDate>Fri, 22 Mar 2013 03:56:43 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Data Explorer]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2902</guid>
		<description><![CDATA[Ok truth be told I am a big time Lakers fan and this season is a big disappointment for me, one of the things that irks me is that the Lakers are being paid the most of all the teams in NBA but lack the results. In this blog post I am going to compare [...]]]></description>
				<content:encoded><![CDATA[<p>Ok truth be told I am a big time Lakers fan and this season is a big disappointment for me, one of the things that irks me is that the Lakers are being paid the most of all the teams in NBA but lack the results. In this blog post I am going to compare the winning pct per team per dollar paid so we can see the results.</p>
<p>First I want to import the data that I need. I am going to use <a href="http://blogs.msdn.com/b/dataexplorer/" target="_blank">Data Explorer</a> to import the data into Excel and then I am going to use PowerPivot to analyze the results.</p>
<p>First data source that I am going to use is <a title="http://espn.go.com/nba/salaries/_/page/1" href="http://espn.go.com/nba/salaries/_/page/1">http://espn.go.com/nba/salaries/_/page/1</a></p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb.png" width="362" height="249" border="0" /></a></p>
<p>this I want to combine with <a title="http://espn.go.com/nba/standings/_/group/1" href="http://espn.go.com/nba/standings/_/group/1">http://espn.go.com/nba/standings/_/group/1</a></p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb1.png" width="372" height="217" border="0" /></a></p>
<p>I start by importing the standings, go to Excel and the Data Explorer tab and select “from web”</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb2.png" width="343" height="255" border="0" /></a></p>
<p>Paste in the URL and select Table 0</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image3.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb3.png" width="600" height="170" border="0" /></a></p>
<p>Now I want to remove the first row so I can select Remove Top Rows and select the first row and I also select Use first Row as Headers:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image4.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb4.png" width="242" height="244" border="0" /></a></p>
<p>Now I am only interested in the Team name and win – loss pct so I am removing all other rows by selecting Hide Columns:&#8221;</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image5.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb5.png" width="502" height="209" border="0" /></a></p>
<p>Now I want to clean up the Team name to remove unwanted characters:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image6.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb6.png" width="244" height="194" border="0" /></a></p>
<p>I select Replace Values and remove y – and x- with an empty value.</p>
<p>Ok I am happy with the result and I press Done to import the data into Excel:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image7.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb7.png" width="434" height="246" border="0" /></a></p>
<p>I want to rename the Query to NBA Standings and Load it to the Data model.</p>
<p>Next up is import a list of all the players and their Salaries. Again the same thing Import from web, this time as is:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image8.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb8.png" width="423" height="180" border="0" /></a></p>
<p>I press OK to import and rename the Table:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image9.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb9.png" width="478" height="275" border="0" /></a></p>
<p>Now we only see 40 players here as this webpage we import from actually has multiple pages. The cool thing about Data Explorer is that under the covers its is a special language called M. What we are going to do now is make a function out of the import function that we can call iteratively for each page.</p>
<p>First I need to make sure I can actually edit queries, I go to the Data Explorer tab and select “Enable Advanced Query Editing”:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image10.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb10.png" width="494" height="153" border="0" /></a></p>
<p>Now I go back to the table I just imported and click on “Filter &amp; Shape” and click on this little “script” icon that now appears:&#8221;</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image11.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb11.png" width="244" height="226" border="0" /></a></p>
<p>This pops open the script dialog:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image12.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb12.png" width="600" height="460" border="0" /></a>,</p>
<p>I change the script to the following:</p>
<blockquote><p>(page) =&gt; let<br />
Source = Web.Page(Web.Contents(&#8220;<a href="http://espn.go.com/nba/salaries/_/page/&quot;">http://espn.go.com/nba/salaries/_/page/&#8221;</a> &amp; Number.ToText(page))),<br />
Data0 = Source{0}[Data]<br />
in<br />
Data0</p></blockquote>
<p>This will add a empty sheet to excel with just this function, nothing can be shown on the table but it needs to be there, I also renamed the table to Query.</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image13.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb13.png" width="432" height="214" border="0" /></a></p>
<p>Ok now I want to use that function for all 14 pages. I go to Data Explorer and select import from other sources, “Write Query”.</p>
<p>This opens a blank query window:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image14.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb14.png" width="493" height="230" border="0" /></a></p>
<p>Here I paste in the following:</p>
<blockquote><p>let<br />
Source = Table.Combine(List.Transform({1..14}, Query))<br />
in<br />
Source</p></blockquote>
<p>this will combine the results of a the query function executed from 1 to 14</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image15.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb15.png" width="544" height="337" border="0" /></a></p>
<p>Press OK and the all data (527 rows instead of 40) will be added to the sheet:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image16.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb16.png" width="599" height="373" border="0" /></a></p>
<p>Pretty awesome right ? Now lets add this to the model as well by clicking load to data model:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image17.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb17.png" width="547" height="196" border="0" /></a></p>
<p>Quick tip, <strong>don’t</strong> rename the tables. This doesn’t work in the current build of Data Explore and will screw up the connection to the model.</p>
<p>Now I want to create a relationship but we have problem, how do I relate:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image18.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb18.png" width="134" height="236" border="0" /></a></p>
<p>with</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image19.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb19.png" width="210" height="286" border="0" /></a></p>
<p>We need to make the values in the column the same. I will plan to extract the city from team in dataset 2 to combine it with dataset 1 and remove LA from dataset1.</p>
<p>So I click on filter and reshape again at the salaries. I select the column and select by delimiter, select space and at the right-most delimiter.</p>
<p>That will give me:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image20.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb20.png" width="514" height="214" border="0" /></a></p>
<p>Now I rename the Team.1 to City and Team.2 to Team. The last problem is that LA has two teams. You can see that in the first dataset they solved that by deviating from the norm by adding LA Lakers and LA Clippers. I need to do the same here.</p>
<p>First I rename Los Angeles to LA. Now I add a new column that based on my expression add the team name if the city is Lakers. I do right mouse click on the Salary column and select Insert column, Custom… This opens a new window where I can type a expression. What I added was:</p>
<blockquote><p>if [City]=&#8221;LA&#8221; then [City] &amp; &#8221; &#8221; &amp; [TEAM] else [City]</p></blockquote>
<p>This will give me the result that I want (I also renamed the columns):</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image21.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb21.png" width="518" height="168" border="0" /></a></p>
<p>Except that the steps did not anticipate a NBA team with two words “Trail Blazers” . So I added a special step for that to the formula&#8221;:</p>
<blockquote><p>if [City]=&#8221;LA&#8221; then [City] &amp; &#8221; &#8221; &amp; [TEAM] else if [City]=&#8221;Portland Trail&#8221; then &#8220;Portland&#8221; else [City]</p></blockquote>
<p>I press OK and reimport the data.</p>
<p>&nbsp;</p>
<p>Now I am able to create a relationship in PowerPivot:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image22.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb22.png" width="355" height="178" border="0" /></a></p>
<p>and start my Analysis by creating a Pivottable. I also formatted PCT and Salary in PowerPivot to get a better view.</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image23.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb23.png" width="215" height="468" border="0" /></a></p>
<p>There is a large amount of players in there that are not assigned to any team. I want to filter those out of the result set. So I go back to Data Explorer and deselect players with an empty city:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image24.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb24.png" width="337" height="223" border="0" /></a></p>
<p>This gets rid of 100+ players that I don’t care about.</p>
<p>Now lets look at the data and add a measure that determine the PCT of Salary compared to all other teams.</p>
<p>I add the following measure to PowerPivot:</p>
<blockquote><p>Salary all teams:=CALCULATE(sum(Query1[SALARY]),ALL(Query))</p></blockquote>
<p>The first shocking result was when this measure returned the value of 1.8 billion ..:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image25.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb25.png" width="501" height="76" border="0" /></a></p>
<p>Now I add a percentage of salary for each team against all salaries.</p>
<blockquote><p>pct Salary:=sum(Query1[SALARY])/[Salary all teams]</p></blockquote>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image26.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb26.png" width="426" height="412" border="0" /></a></p>
<p>To make it a little bit more clear instead of PCT I also create a rank:</p>
<blockquote><p>Rank by PCT of winnings:=RANKX(all(Query[NBA]),[Sum of PCT])</p></blockquote>
<p>this really gives you an idea that money doesn’t buy you everything:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image27.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb27.png" width="527" height="314" border="0" /></a></p>
<p>The most interesting one is Indiana all the way down with almost half the salary costs as the Lakers at 7th best team in the NBA:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image28.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb28.png" width="555" height="126" border="0" /></a></p>
<p>and the teams above and below the Lakers earn less <strong><span style="font-size: small;">together</span></strong>  then the Lakers themselves..</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image29.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb29.png" width="560" height="111" border="0" /></a></p>
<p>Next up I would like to add a measure that will calculate the salary per player. So add the following two measures:</p>
<blockquote><p>nr of players:=COUNTROWS(Query1)</p>
<p>Salary per player:=sum(Query1[SALARY]) / [nr of players]</p></blockquote>
<p>&nbsp;</p>
<p>Unfortunately that didn’t give us much interesting information, besides what we already know. It is interesting to see that a few teams have almost 20 players on their team:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image30.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb30.png" width="544" height="180" border="0" /></a></p>
<p>While Chicago and the Lakers are not even capable of doing 5 on 5 in training ..</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image31.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/image_thumb31.png" width="547" height="158" border="0" /></a></p>
<p>Hope that gives you some idea of the power of Data Explorer and PowerPivot together.</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/pJku8p8b1Mg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/nba-team-spending-and-their-results-with-excel-powerpivot-and-data-explorer/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What is eating up my memory the PowerPivot / Excel edition</title>
		<link>http://www.powerpivotblog.nl/what-is-eating-up-my-memory-powerpivot-excel-edition</link>
		<comments>http://www.powerpivotblog.nl/what-is-eating-up-my-memory-powerpivot-excel-edition#comments</comments>
		<pubDate>Fri, 15 Mar 2013 23:34:20 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2815</guid>
		<description><![CDATA[A common question asked is what columns in my model are using the most memory. Earlier I created a workbook that was able to get the memory for a Tabular server which you can download here but that didn&#8217;t work with an embedded Excel Data model or PowerPivot workbook. But I recently found a new way that would [...]]]></description>
				<content:encoded><![CDATA[<p>A common question asked is what columns in my model are using the most memory. Earlier I created a workbook that was able to get the memory for a Tabular server which you can download <a href="http://www.powerpivotblog.nl/what-is-using-all-that-memory-on-my-analysis-server-instance">here</a> but that didn&#8217;t work with an embedded Excel Data model or PowerPivot workbook.</p>
<p>But I recently found a new way that would allow me to get this information in PowerPivot / Excel 2013 using a macro. Many thanks to <a href="http://www.excelguru.ca/blog/">Ken Puls </a> who helped me clean up the macro and give me some great Excel tips. It always great to see SQL and Excel folks learn things from each other <img src='http://www.powerpivotblog.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Thanks to his help this macro, once created, will be accessible for all workbooks without having to change the individual workbooks.</p>
<p>This macro uses the Excel connection retrieved from the Excel OM and sends a SSAS DMV query to the embedded model to retrieve memory information. Using the connection to send custom query is not a scenario that is supported, meaning custom queries send through the connection will not be guaranteed to work in any future updates of the product.</p>
<p>When you run this macro in any workbook that contains a Excel Data Model will give you a new worksheet with a table containing all tables, columns, datatype and MemorySize (KB). It also has a Pivottable that aggregates the results and is sorted by size:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/sheet.png"><img class="alignnone size-full wp-image-2817" alt="sheet" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/03/sheet.png" width="796" height="367" /></a></p>
<p>The SSAS DMV used to get this information does only return the segment size of a column, this is not all the memory that is used per column but will give enough information to get an good idea of the actual usage. For more details on the internals of the Tabular engine please watch <a href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2012/DBI414">this teched</a> presentation</p>
<p>To get this Macro available for all you workbooks in Excel the following steps are needed.</p>
<ul>
<li>If you haven’t already exposed the Developer tab in Excel, do that first. (right mouse click on the ribbon)</li>
<li>On the developer tab, record a new macro, and choose to store it in your “Personal Workbook”</li>
<li>Stop recording</li>
<li>Press Alt+F11 to get into the Visual basic editor</li>
<li>Find Module1 in the personal macro workbook</li>
<li>Replace ALL the code for the code you just recorded in there with the code in the attached file</li>
<li>Go back to Excel</li>
<li>Press Alt + F8 and run the Macro</li>
</ul>
<p>The entire Macro is as following:</p>
<pre lang="Visual BASIC" line="1">Option Explicit

Sub GetMemoryUsage()
    Dim wbTarget As Workbook
    Dim ws As Worksheet
    Dim rs As Object
    Dim lRows As Long
    Dim lRow As Long
    Dim sReportName As String
    Dim sQuery As String
    sReportName = "Memory_Usage"

    'Suppress alerts and screen updates
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With

    'Bind to active workbook
    Set wbTarget = ActiveWorkbook

    'Check if a worksheet already exists
    Err.Clear
    On Error Resume Next
    Set ws = wbTarget.Worksheets(sReportName)
    If Err.Number = 0 Then
        'Worksheet found
        If MsgBox("A memory usage sheet workbook is already detected, " &amp; _
            "do you want to remove the existing one and continue?", vbYesNo) = vbYes Then
                ws.Delete
        Else
            GoTo ExitPoint
        End If
    End If

    On Error GoTo ErrHandler

    'Make sure the model is loaded
    wbTarget.Model.Initialize

    'Send query to the model
    sQuery = "SELECT dimension_name, attribute_name, DataType,(dictionary_size/1024) AS dictionary_size " &amp; _
        "FROM $system.DISCOVER_STORAGE_TABLE_COLUMNS " &amp; _
        "WHERE dictionary_size &gt; 0"
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open sQuery, wbTarget.Model.DataModelConnection.ModelConnection.ADOConnection
    lRow = rs.RecordCount

    If lRow &gt; 0 Then
        'Add report worksheet
        Set ws = wbTarget.Worksheets.Add
        With ws
            .Name = sReportName
            .Range("A1").FormulaR1C1 = "Table"
            .Range("B1").FormulaR1C1 = "Column"
            .Range("C1").FormulaR1C1 = "DataType"
            .Range("D1").FormulaR1C1 = "MemorySize (KB)"

            lRows = 2
            rs.MoveFirst

            Do While Not rs.EOF
                'Add the data to the rows
                .Range("A" &amp; lRows).FormulaR1C1 = rs("dimension_name")
                .Range("B" &amp; lRows).FormulaR1C1 = rs("attribute_name")
                .Range("C" &amp; lRows).FormulaR1C1 = rs("DataType")
                .Range("D" &amp; lRows).FormulaR1C1 = rs("dictionary_size")
                lRows = lRows + 1
                rs.movenext
            Loop

            'Format the Memory Size field
            .Columns("D:D").NumberFormat = "#,##0.00"

            'Create table
            .ListObjects.Add(xlSrcRange, .Range("$A$1:$D$" &amp; lRow + 1), , xlYes).Name = "MemorySizeTable"
        End With

        'Create PivotTable
        wbTarget.PivotCaches.Create(SourceType:=xlDatabase, _
            SourceData:="MemorySizeTable", _
            Version:=xlPivotTableVersion15).CreatePivotTable _
            TableDestination:="Memory_Usage!R2C7", _
            TableName:="MemoryTable", _
            DefaultVersion:=xlPivotTableVersion15

        'Modify the PivotTable
        With ws
            With .PivotTables("MemoryTable")
                With .PivotFields("Table")
                    .Orientation = xlRowField
                    .Position = 1
                    .AutoSort xlDescending, "Sum of MemorySize (KB)"
                End With
                With .PivotFields("Column")
                    .Orientation = xlRowField
                    .Position = 2
                    .AutoSort xlDescending, "Sum of MemorySize (KB)"
                End With
                .AddDataField .PivotFields("MemorySize (KB)"), "Sum of MemorySize (KB)", xlSum
                .PivotFields("Table").AutoSort xlDescending, "Sum of MemorySize (KB)"
                .PivotFields("Column").AutoSort xlDescending, "Sum of MemorySize (KB)"
             End With

            'Format the Memory Size field in the PivotTable
            .Columns("H:H").NumberFormat = "#,##0.00"

            'Add conditional formatting
            With .Range("H3")
                .FormatConditions.AddDatabar
                .FormatConditions(.FormatConditions.Count).ShowValue = True
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                With .FormatConditions(1)
                    .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
                    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
                    With .BarColor
                        .Color = 13012579
                        .TintAndShade = 0
                    End With
                    .BarFillType = xlDataBarFillGradient
                    .Direction = xlContext
                    .NegativeBarFormat.ColorType = xlDataBarColor
                    .BarBorder.Type = xlDataBarBorderSolid
                    .NegativeBarFormat.BorderColorType = xlDataBarColor
                    With .BarBorder.Color
                        .Color = 13012579
                        .TintAndShade = 0
                    End With
                    .AxisPosition = xlDataBarAxisAutomatic
                    With .AxisColor
                        .Color = 0
                        .TintAndShade = 0
                    End With
                    With .NegativeBarFormat.Color
                        .Color = 255
                        .TintAndShade = 0
                    End With
                    With .NegativeBarFormat.BorderColor
                        .Color = 255
                        .TintAndShade = 0
                    End With
                    .ScopeType = xlSelectionScope
                    .ScopeType = xlFieldsScope
                End With
            End With

            With .Range("H4")
                .FormatConditions.AddDatabar
                .FormatConditions(.FormatConditions.Count).ShowValue = True
                .FormatConditions(.FormatConditions.Count).SetFirstPriority
                With .FormatConditions(1)
                    .MinPoint.Modify newtype:=xlConditionValueAutomaticMin
                    .MaxPoint.Modify newtype:=xlConditionValueAutomaticMax
                    With .BarColor
                        .Color = 15698432
                        .TintAndShade = 0
                    End With
                    .BarFillType = xlDataBarFillGradient
                    .Direction = xlContext
                    .NegativeBarFormat.ColorType = xlDataBarColor
                    .BarBorder.Type = xlDataBarBorderSolid
                    .NegativeBarFormat.BorderColorType = _
                        xlDataBarColor
                    With .BarBorder.Color
                        .Color = 15698432
                        .TintAndShade = 0
                    End With
                    .AxisPosition = xlDataBarAxisAutomatic
                    With .AxisColor
                        .Color = 0
                        .TintAndShade = 0
                    End With
                    With .NegativeBarFormat.Color
                        .Color = 255
                        .TintAndShade = 0
                    End With
                    With .NegativeBarFormat.BorderColor
                        .Color = 255
                        .TintAndShade = 0
                    End With
                    .ScopeType = xlSelectionScope
                    .ScopeType = xlFieldsScope
                End With
            End With

            'Collapse the PivotTable
            .PivotTables("MemoryTable").PivotFields("Table").ShowDetail = False

            'Set selection to top
            .Range("MemorySizeTable[[#Headers],[Table]]").Select
        End With
    Else
        MsgBox "No model available", vbOKOnly
    End If
    rs.Close

ExitPoint:
    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With
    Set rs = Nothing
    Exit Sub

ErrHandler:
    MsgBox "An error occured - " &amp; Err.Description, vbOKOnly
    Resume ExitPoint
End Sub</pre>
<p>Download a sample workbook <a href="http://sdrv.ms/ZqQHa6">here</a>. The Macro is applied to this workbook only for you to be able to download it, to get this available for all workbooks go through the steps above.</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/s2RMzgQfanE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/what-is-eating-up-my-memory-powerpivot-excel-edition/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using Traditional SSRS parameterized reports against a Analysis Services Tabular model using DAX</title>
		<link>http://www.powerpivotblog.nl/using-traditional-ssrs-parameterized-reports-against-a-analysis-services-tabular-model-using-dax</link>
		<comments>http://www.powerpivotblog.nl/using-traditional-ssrs-parameterized-reports-against-a-analysis-services-tabular-model-using-dax#comments</comments>
		<pubDate>Tue, 12 Feb 2013 01:36:35 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Analysis services]]></category>
		<category><![CDATA[Reporting Services]]></category>
		<category><![CDATA[SSAS]]></category>
		<category><![CDATA[SSRS]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2806</guid>
		<description><![CDATA[I get this question every now and then: Is it possible to create a traditional SSRS report with parameters against a tabular model using DAX. Marco already created a great blog post that sums it all up here, but I decided to create a step by step example. Ok I created a simple Tabular model [...]]]></description>
				<content:encoded><![CDATA[<p>I get this question every now and then: Is it possible to create a traditional SSRS report with parameters against a tabular model using DAX. Marco already created a great blog post that sums it all up <a href="http://sqlblog.com/blogs/marco_russo/archive/2012/01/05/use-parameters-in-your-dax-queries.aspx" target="_blank">here</a>, but I decided to create a step by step example.</p>
<p><span id="more-2806"></span></p>
<p>Ok I created a simple Tabular model in SSDT:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb1.png" width="378" height="414" border="0" /></a></p>
<p>The model does not contain any measures, just tables and relationships and marked the date table. I didn’t want to complicate the Tabular model by adding measures specific for a single project.</p>
<p>&nbsp;</p>
<p>From this Tabular model I want to create a SSRS report that allows:</p>
<ul>
<li>Selection of year, default select the last year we have data (what defines the current year ? <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/wlEmoticon-smile1.png" />)</li>
<li>Select a product color</li>
</ul>
<p>And shows:</p>
<ul>
<li>Sales per product for the selected year</li>
<li>Sales per product for the previous year</li>
<li>Sales per product YoY</li>
<li>Sales per product YoY %</li>
<li>Sales YoY product rank</li>
</ul>
<ul>Ok lets get started. In SSDT where created the Tabular Project I added the Report project to the same solution.</ul>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb2.png" width="208" height="244" border="0" /></a></p>
<p>&nbsp;</p>
<p>As Datasource for my RS project I used the workspace database that I have set up for my tabular model:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image3.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb3.png" width="428" height="315" border="0" /></a></p>
<p>Next I created a new report and followed the wizard until I got to the Query Builder:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image4.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb4.png" width="405" height="378" border="0" /></a></p>
<p>Press the Query Builder button and click on the DMX data mining button and switch to manual query mode:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image5.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb5.png" width="447" height="338" border="0" /></a></p>
<p>The reason that we need to switch to DMX data mining mode is that the designer tries to parse the MDX, and as we are going to write DAX the parser will not understand. Marco explained this bit very well.</p>
<p>Next I paste in a simple DAX query expression to get through the wizard, it doesn&#8217;t take well to complex DAX:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image6.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb6.png" width="394" height="370" border="0" /></a></p>
<p>Finish the wizard and run the report:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image7.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb7.png" width="226" height="352" border="0" /></a></p>
<p>Now we have our first DAX based report.</p>
<p>Ok now lets add the parameters. I usually create shared datasets for these. So I create one for years:</p>
<blockquote><p>evaluate<br />
SUMMARIZE<br />
(<br />
FactInternetSales,<br />
DimDate[CalendarYear]<br />
)</p>
<p>order by DimDate[CalendarYear]</p></blockquote>
<p>One to get the last year we have sales</p>
<blockquote><p>EVALUATE<br />
TOPN(1,<br />
SUMMARIZE<br />
(<br />
FactInternetSales,<br />
DimDate[CalendarYear]<br />
),<br />
CALCULATE(MAX(DimDate[CalendarYear])))</p></blockquote>
<p>&nbsp;</p>
<p>and one for Product Color (we will change this one later)</p>
<blockquote><p>EVALUATE<br />
SUMMARIZE<br />
(<br />
FactInternetSales,<br />
DimProduct[Color]<br />
)<br />
ORDER BY DimProduct[Color]</p></blockquote>
<p>What you might notice here is that I use Summarize, this will make sure it only return values that are used in a relationship with the FactInternetSales table. I also order the outcome to make sure we get the “right” order in the report.</p>
<p>Add all the parameters to the report:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image8.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb8.png" width="194" height="187" border="0" /></a></p>
<p>This will add the parameters over my report:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image9.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb9.png" width="441" height="173" border="0" /></a></p>
<p>Now for the main report I need a more extensive query that allows filtering by parameters and creates some interesting measures on the fly. This is the measure that I created for this purpose:</p>
<blockquote><p>DEFINE MEASURE FactInternetSales[SumofSales] = SUM(FactInternetSales[SalesAmount])<br />
MEASURE FactInternetSales[SumofSales PY] = CALCULATE(FactInternetSales[SumofSales], SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))<br />
MEASURE FactInternetSales[SumofSales YoY] = FactInternetSales[SumofSales] &#8211; FactInternetSales[SumofSales PY]<br />
MEASURE FactInternetSales[SumofSales YoY pct] = FactInternetSales[SumofSales]  / FactInternetSales[SumofSales PY]</p>
<p>EVALUATE<br />
CALCULATETABLE<br />
(<br />
ADDCOLUMNS<br />
(<br />
FILTER(<br />
CROSSJOIN(<br />
VALUES(DimDate[CalendarYear]),<br />
VALUES(DimProduct[EnglishProductName]))<br />
,FactInternetSales[SumofSales] &gt; 0<br />
),<br />
&#8220;Sum of Sales&#8221;,FactInternetSales[SumofSales],<br />
&#8220;Sales last year&#8221;,FactInternetSales[SumofSales PY],<br />
&#8220;Sales YoY&#8221;,FactInternetSales[SumofSales YoY],<br />
&#8220;Sales YoY pct&#8221;,FactInternetSales[SumofSales YoY pct],<br />
&#8220;Rank&#8221;, RANKX(FILTER(<br />
CROSSJOIN(<br />
VALUES(DimDate[CalendarYear]),<br />
VALUES(DimProduct[EnglishProductName]))<br />
,FactInternetSales[SumofSales] &gt; 0<br />
)<br />
,FactInternetSales[SumofSales YoY])<br />
),<br />
DimDate[CalendarYear] = 2003,<br />
DimProduct[Color] = &#8220;Red&#8221;<br />
)<br />
ORDER BY [Rank]</p></blockquote>
<p>Lets take this step by step. First I create the measures in the define statement, these are pretty straightforward (except the RANK, I will come to that in a bit):</p>
<blockquote><p>DEFINE MEASURE FactInternetSales[SumofSales] = SUM(FactInternetSales[SalesAmount])<br />
MEASURE FactInternetSales[SumofSales PY] = CALCULATE(FactInternetSales[SumofSales], SAMEPERIODLASTYEAR(DimDate[FullDateAlternateKey]))<br />
MEASURE FactInternetSales[SumofSales YoY] = FactInternetSales[SumofSales] &#8211; FactInternetSales[SumofSales PY]<br />
MEASURE FactInternetSales[SumofSales YoY pct] = FactInternetSales[SumofSales]  / FactInternetSales[SumofSales PY]</p></blockquote>
<p>Next I start with the Evaluate to return a tabular result and order the result set by Rank:</p>
<blockquote><p>ORDER BY [Rank]</p></blockquote>
<p>Then I add CALCULATETABLE that will make sure the returned table will be filtered by</p>
<blockquote><p>DimDate[CalendarYear] = 2003,<br />
DimProduct[Color] = &#8220;Red&#8221;</p></blockquote>
<p>These will be parameterized later.</p>
<p>The core of the query is result set of a CROSSJOIN between CalendarYear and  EnglishProductName. The results are FILTERed where the crossjoin combination has make any sales.</p>
<blockquote><p>FILTER(<br />
CROSSJOIN(<br />
VALUES(DimDate[CalendarYear]),<br />
VALUES(DimProduct[EnglishProductName]))<br />
,FactInternetSales[SumofSales] &gt; 0<br />
)</p></blockquote>
<p>to this CalendarYear and  EnglishProductName combination that have sales we add some columns</p>
<blockquote><p>ADDCOLUMNS<br />
(<br />
FILTER(<br />
CROSSJOIN(<br />
VALUES(DimDate[CalendarYear]),<br />
VALUES(DimProduct[EnglishProductName]))<br />
,FactInternetSales[SumofSales] &gt; 0<br />
),<br />
&#8220;Sum of Sales&#8221;,FactInternetSales[SumofSales],<br />
&#8220;Sales last year&#8221;,FactInternetSales[SumofSales PY],<br />
&#8220;Sales YoY&#8221;,FactInternetSales[SumofSales YoY],<br />
&#8220;Sales YoY pct&#8221;,FactInternetSales[SumofSales YoY pct],<br />
&#8220;Rank&#8221;, RANKX(FILTER(<br />
CROSSJOIN(<br />
VALUES(DimDate[CalendarYear]),<br />
VALUES(DimProduct[EnglishProductName]))<br />
,FactInternetSales[SumofSales] &gt; 0<br />
)<br />
,FactInternetSales[SumofSales YoY])<br />
)</p></blockquote>
<p>Interestingly in order for us to get RANK properly evaluated we couldn’t use the measure as that would push the calculation to outside the crossjoin calculation filter context. Adding it inline with the addcolumns allowed the filter context to be properly evaluated.</p>
<p>Executing this in SSMS gives us the following table:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image10.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb10.png" width="569" height="228" border="0" /></a></p>
<p>Now I went back to RS and opened the dataset properties and pasted the above query into the query field:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image11.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb11.png" width="396" height="406" border="0" /></a></p>
<p>Now this doesn’t refresh the fields, so you need to work around this again. Right mouse click on the query, this opens the query but with an error message cannot find cube. Press OK and select the “Model” cube. Now click on the DM icon again, say yes to result loss message and turn off query UI mode (yes its cumbersome) and paste in the query:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image12.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb12.png" width="411" height="308" border="0" /></a></p>
<p>Press OK and now you will see the Dataset has been updated with the right fields:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image13.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb13.png" width="194" height="174" border="0" /></a></p>
<p>Now you can create the report you want:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image14.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb14.png" width="600" height="311" border="0" /></a></p>
<p>And run it:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image15.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb15.png" width="551" height="268" border="0" /></a></p>
<p>As you can see I added some expressions to make it look pretty <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/wlEmoticon-smile1.png" />. Now for the last step we need to have the query respect the parameters.</p>
<p>Select the dataset and as you could see in Marco’s blog post we need to change the query into an expression. Go back to the dataset properties:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image16.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb16.png" width="350" height="359" border="0" /></a></p>
<p>And click on the formula button. Now instead of a plain string we need to make it a VB like string:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image17.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb17.png" width="565" height="402" border="0" /></a></p>
<p>Make sure lines are ended with vbCrLf (A big thanks to Jason Tremper from the RS team that helped me figure this out).</p>
<p>In the bottom part replace the hard coded parameters values with the parameter values:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image18.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb18.png" width="553" height="132" border="0" /></a></p>
<p><span style="color: #ff6600;">Update</span>: both Chris Webb and Greg Galloway pointed out that I should be able to use parameters directly in the dataset. I tried that before and got a error message. I tried again today and it worked so I must have done something wrong last time. So here is the preferred alternative to the method above.</p>
<p>Open the dataset properties and select parameters. Add both parameters:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/dspar.png"><img class="alignnone  wp-image-2810" alt="dspar" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/dspar.png" width="502" height="512" /></a></p>
<p>&nbsp;</p>
<p>Now  go back to the query and just past the entire query in, as is. No need to make it into a string as I had to do above:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/query.png"><img class="alignnone  wp-image-2811" alt="query" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/query.png" width="717" height="506" /></a></p>
<p>&nbsp;</p>
<p>Now for the last part, replace the hardcoded strings with the parameters:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/param.png"><img class="alignnone size-full wp-image-2812" alt="param" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/param.png" width="586" height="230" /></a></p>
<p>&nbsp;</p>
<p>And voila that is all there is to it.</p>
<p>I also applied the same logic to the Color parameter where I wanted to make sure I only show the colors that have sales in the same year:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image19.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb19.png" width="566" height="398" border="0" /></a></p>
<p>Adding it all together you get this report:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image20.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/02/image_thumb20.png" width="544" height="384" border="0" /></a></p>
<p>I think this is a very valuable way of creating reports, I wish I had this when I still was a consultant. Its pretty easy to template and use over time and time again without having to update and change your model. I feel that it also is a little easier this way than using MDX, although it might have to do with a personal preference.</p>
<p>You can download the project <a href="https://skydrive.live.com/redir?resid=7F4E0559CC74581A!1119&amp;authkey=!apmi7P6sDzk%24" target="_blank">here</a>. Its based on Adventureworks.</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/EqsYoeUYDz0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/using-traditional-ssrs-parameterized-reports-against-a-analysis-services-tabular-model-using-dax/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Filtering results to only show top x results in Power View chart</title>
		<link>http://www.powerpivotblog.nl/filtering-results-to-only-show-top-x-results-in-power-view-chart</link>
		<comments>http://www.powerpivotblog.nl/filtering-results-to-only-show-top-x-results-in-power-view-chart#comments</comments>
		<pubDate>Sat, 26 Jan 2013 01:10:47 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2755</guid>
		<description><![CDATA[&#160; A question came up recently on how can I limit the number of elements on a chart in Power View by a custom calculation. Imagine you have a chart in Power View with too many data points to make anything out and you want to filter out the “noise”. Just give me the most [...]]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>A question came up recently on how can I limit the number of elements on a chart in Power View by a custom calculation. Imagine you have a chart in Power View with too many data points to make anything out and you want to filter out the “noise”. Just give me the most profitable datapoints.</p>
<p>I created this chart with just a few datapoints. I love how Power View and Bing maps allow me to put any location in and it just knows where to plot it !.</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image13.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb13.png" width="168" height="340" border="0" /></a></p>
<p>Then I create a chart:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image14.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb14.png" width="509" height="356" border="0" /></a></p>
<p>Now I create a DAX measure that determines the Rank of each postalcode by sum of data:</p>
<blockquote><p>=RANKX(ALL(CityData[PostalCode]),[Sum of Data])</p></blockquote>
<p>This measure will compare the result of [Sum of Data] for the current data point against the result of [Sum of Data] for all rows in ALL(CityData[PostalCode]) and return the relative rank of those two numbers.</p>
<p>In a table this shows us as following:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image15.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb15.png" width="336" height="207" border="0" /></a></p>
<p>Now I put that measure in the map filter area and start filtering on it. This gives us only the top 2 ranked cities:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image16.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb16.png" width="576" height="328" border="0" /></a></p>
<p>The rank is automatically measure calculated for each data point in the chart (like what you see in the table in the previous image).</p>
<p>Download the sample workbook <a href="https://skydrive.live.com/redir?resid=7F4E0559CC74581A!1099&amp;authkey=!apmi7P6sDzk%24">here</a>.</p>
<p>&nbsp;</p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/MnthzqAZFyI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/filtering-results-to-only-show-top-x-results-in-power-view-chart/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hardware Sizing a Analysis Services Tabular Database</title>
		<link>http://www.powerpivotblog.nl/hardware-sizing-a-analysis-services-tabular-database</link>
		<comments>http://www.powerpivotblog.nl/hardware-sizing-a-analysis-services-tabular-database#comments</comments>
		<pubDate>Wed, 16 Jan 2013 23:23:19 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Analysis services]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2744</guid>
		<description><![CDATA[I just quickly wanted to point out that that there is now a whitepaper available on &#8220;Hardware Sizing a Tabular Solution&#8221; You can download it here: http://msdn.microsoft.com/en-us/library/jj874401.aspx]]></description>
				<content:encoded><![CDATA[<p>I just quickly wanted to point out that that there is now a whitepaper available on &#8220;Hardware Sizing a Tabular Solution&#8221;</p>
<p>You can download it here: <a href="http://msdn.microsoft.com/en-us/library/jj874401.aspx">http://msdn.microsoft.com/en-us/library/jj874401.aspx</a></p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/EpRfXG9FNiY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/hardware-sizing-a-analysis-services-tabular-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerPivot Use Case: Getting the active products between a date range using DAX</title>
		<link>http://www.powerpivotblog.nl/powerpivot-use-case-getting-the-active-products-between-a-date-range-using-dax</link>
		<comments>http://www.powerpivotblog.nl/powerpivot-use-case-getting-the-active-products-between-a-date-range-using-dax#comments</comments>
		<pubDate>Tue, 08 Jan 2013 23:10:49 +0000</pubDate>
		<dc:creator>Kasper de Jonge</dc:creator>
				<category><![CDATA[Analysis services]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[PowerPivot]]></category>

		<guid isPermaLink="false">http://www.powerpivotblog.nl/?p=2739</guid>
		<description><![CDATA[I have been getting this question a few times in the last week, e.g. in my ask a questions page here, on how we can get the number of active products between two time intervals in Excel. Lets answer the question on my ask a questions page in todays blog post. The question was: DESIRED [...]]]></description>
				<content:encoded><![CDATA[<p>I have been getting this question a few times in the last week, e.g. in my ask a questions page <a href="http://www.powerpivotblog.nl/ask-you-questions-here#comment-4561" target="_blank">here</a>, on how we can get the number of active products between two time intervals in Excel. Lets answer the question on my ask a questions page in todays blog post.</p>
<p>The question was:</p>
<blockquote><p>DESIRED OUTPUT: Pivot table showing count of asset available by Month; Column Headings = Months &amp; Year; Row Headings = Class.</p>
<p>TABLE1: Includes a list of assets and corresponding Class, Acquired date, and Disposed date.</p>
<p>Asset,Class,Acquired,Disposed<br />
A,TEL,2/16/2010,10/06/2011<br />
B,LBH,3/20/2010,05/23/2012<br />
C,RBH,4/11/2010,06/22/2011<br />
D,TRJ,1/17/2011,09/05/2012<br />
E,DGH,5/9/2011,05/02/2012<br />
F,DGH,7/18/2011,03/13/2012<br />
G,RBH,9/23/2011,01/21/2012<br />
H,TRJ,5/28/2012,06/07/2012<br />
I,THG,7/2/2012,10/11/2012<br />
J,TBD,8/6/2012,12/02/2012</p>
<p>TABLE2: Date Table including fields for Date, Month, and Year</p>
<p>EXAMPLE OUTPUT: Based on the data above, the pivot table output for June-August of 2011 would be as follows…</p>
<p>Year: 2011<br />
Month: Jun, Jul, Aug<br />
DGH, 1.0, 2.0, 2.0<br />
LBH, 1.0, 1.0, 1.0<br />
RBH, 1.0, 0.0, 0.0<br />
TBD, 0.0, 0.0, 0.0<br />
TEL, 1.0, 1.0, 1.0<br />
THG, 0.0, 0.0, 0.0<br />
TRJ, 1.0, 1.0, 1.0</p></blockquote>
<p>Ok lets solve this using DAX.</p>
<p><span id="more-2739"></span></p>
<p>First I load the table into Excel 2013, make a table out of it and push it to the Excel data model.</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb.png" width="340" height="255" border="0" /></a></p>
<p>Observe that I changed the dates to have all dates be in 2011 to make it easier for us to debug.</p>
<p>Next I created a date table in Excel:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb1.png" width="202" height="259" border="0" /></a></p>
<p>Back in Excel I create the pivottable like requested in the question:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image2.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb2.png" width="524" height="211" border="0" /></a></p>
<p>First things first, I would like to make sure to sort the months in its natural order. We can do that using the PowerPivot add-in. I created a calculated column that determines the month number:</p>
<blockquote><p>=MONTH([Date])</p></blockquote>
<p>I then hide the column and use the sort by other column button to tell the Data model to sort Month by Monthnumber</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image3.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb3.png" width="546" height="377" border="0" /></a></p>
<p>This results in the months sorted “right” in the pivottable:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image4.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb4.png" width="548" height="217" border="0" /></a></p>
<p>Now back to the real problem. Notice that I have <strong>NOT </strong>created a relationship between the two tables.</p>
<p>First thing that I want to do is create a measure that counts the number of facts</p>
<blockquote><p>Nr facts:=COUNTROWS(Facts)</p></blockquote>
<p>In the result below this does the dates are not taken into account, but its takes care of counting the facts for the relationships that are there, like nr of products per class:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image5.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb5.png" width="554" height="215" border="0" /></a></p>
<p>We are going to use DAX for that as we don’t have a relationship type that allows us to do a “between” function. The DAX function I created will look at each row from the fact table for each product where the product is active in the current month (acquired before or in this month and disposed after this month) based on the current row and column in Pivottable.</p>
<p>The DAX I wrote to do is the following:</p>
<blockquote><p>Active Facts:=CALCULATE([Nr facts],<br />
FILTER(Facts,<br />
Facts[Acquired] &lt;= MAX(Dates[Date])<br />
&amp;&amp; Facts[Disposed] &gt;= MIN(Dates[Date])</p>
<p>))</p></blockquote>
<p>What does this function do ? First it will execute this function in each and every cell of this pivottable, lets take the first cell:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image6.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb6.png" width="545" height="241" border="0" /></a></p>
<p>The values in this cell will be filtered to Fact[class] = “DGH” and Date[Month] =”Jan” based on the values on rows and column for this cell, the “Fact” table that will thus be filtered by Fact[class]:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image7.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb7.png" width="384" height="102" border="0" /></a></p>
<p>Hence you can see the result of the measure “Nr facts:=COUNTROWS(Facts)” to be 2 in our pivottable image a few images up.</p>
<p>The date table is filtered by the Date[Month] column that is on rows:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image8.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb8.png" width="466" height="79" border="0" /></a></p>
<p>That does not change the value of the measure in our pivottable as there are no relationships between “Date” and “Fact”</p>
<p>&nbsp;</p>
<p>Now to make sure that we can also filter the Fact table by the dates we extend our DAX formula to do the following: Calculate the “NR Facts measure” where the “Fact” table (already automatically filtered by Class)  has Facts[Acquired] before the current selected Dates[Date] or Facts[Disposed] after the current selected Dates[Date]:</p>
<blockquote><p>Active Facts:=CALCULATE([Nr facts],<br />
FILTER(Facts,<br />
Facts[Acquired] &lt;= MAX(Dates[Date])<br />
&amp;&amp; Facts[Disposed] &gt;= MIN(Dates[Date])</p>
<p>))</p></blockquote>
<p>Because the Date table is filtered by the month that we have on columns we get a single date for each cell that we can use in our filter (as each month only has one date in our example). Just to be sure the formula also works when more then one date is selected I use MAX and MIN instead of values, that way we can easily switch to different granularities if we want to later.</p>
<p>There is one flaw of this approach. The Dates[Date] column right now is the beginning of the month, that will never give results for the entire month. So I added a calculated column to the Date table that give me the end date of the current month:</p>
<blockquote><p>=EOMONTH([Date],0)</p></blockquote>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image9.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb9.png" width="600" height="123" border="0" /></a></p>
<p>Now to use it in the function</p>
<blockquote><p>Active Facts:=CALCULATE([Nr facts],<br />
FILTER(Facts,<br />
Facts[Acquired] &lt;= MAX(Dates[EoMonthDate])<br />
&amp;&amp; Facts[Disposed] &gt;= MIN(Dates[Date])</p>
<p>))</p></blockquote>
<p>This will give me the number of ”Facts” grouped by Month and Class:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image10.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb10.png" width="600" height="235" border="0" /></a></p>
<p>I can now swap month for year and still get the right results (because of using MAX / MIN instead of values, thanks Rob Collie for setting this trend <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" alt="Smile" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/wlEmoticon-smile.png" />)</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image11.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb11.png" width="319" height="222" border="0" /></a></p>
<p>Or even add Asset on Rows instead of class and get the right results:</p>
<p><a href="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image12.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://www.powerpivotblog.nl/wp-content/uploads/2013/01/image_thumb12.png" width="600" height="295" border="0" /></a></p>
<p>Hope this gave you a little more insight into DAX. You can download the Excel 2013 workbook here: <a title="https://skydrive.live.com/redir?resid=7F4E0559CC74581A!1088" href="https://skydrive.live.com/redir?resid=7F4E0559CC74581A!1088">https://skydrive.live.com/redir?resid=7F4E0559CC74581A!1088</a></p>
<img src="http://feeds.feedburner.com/~r/kjonge/~4/xvOfyzHm5Tk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotblog.nl/powerpivot-use-case-getting-the-active-products-between-a-date-range-using-dax/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
