<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerPivotPro &#187; DAX</title>
	<atom:link href="http://www.powerpivotpro.com/category/dax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powerpivotpro.com</link>
	<description>Thoughts on PowerPivot, Sharepoint BI and the occasional movie quote</description>
	<lastBuildDate>Tue, 07 Feb 2012 05:01:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Lookups based on date ranges</title>
		<link>http://www.powerpivotpro.com/2012/02/lookups-based-on-date-ranges/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lookups-based-on-date-ranges</link>
		<comments>http://www.powerpivotpro.com/2012/02/lookups-based-on-date-ranges/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 05:01:00 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[Accounting/Financial Techniques]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Quick Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3744</guid>
		<description><![CDATA[Another one from the Mr. XL Forum! …and the word “forum” gives me an excuse for a blast from the past… “What you are about to witness is real. The participants are not actors.&#160; They have agreed to dismiss their tech support cases and have their questions settled here, in our forum: THE POWERPIVOT COURT [...]]]></description>
			<content:encoded><![CDATA[<h3>Another one from the <a href="http://www.mrexcel.com/forum/forumdisplay.php?f=29"><u><font color="#4f81bd">Mr. XL Forum</font></u></a><u><font color="#4f81bd">!</font></u></h3>
<p>…and the word “forum” gives me an excuse for a blast from the past…</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image19.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="PowerPivot Court" border="0" alt="PowerPivot Court" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb18.png" width="462" height="326"></a></p>
<p align="center"><font face="Arial"><font size="2">“What you are about to witness is real. The participants are not actors.&nbsp; They have agreed to dismiss their tech support cases and have their questions settled here, in our forum: <br /><b>THE POWERPIVOT COURT</b></font></font></p>
<p align="center"><strong><a href="http://www.youtube.com/watch?v=7iTqoDH0vFU" target="_blank">(Click here for theme music!)</a></strong></p>
<h3>The much-neglected calculated column</h3>
<p>OK, neglected by me, not by everyone else.&nbsp; At Pivotstream I have the benefit of a great SQL team.&nbsp; Generally speaking, when I need a calculated column, I ask them to provide it.&nbsp; The benefits of doing that are documented several places on this site, <a href="http://www.powerpivotpro.com/2011/11/why-powerpivot-is-better-fed-from-a-database-pt-1/"><strong>including here</strong></a><strong>&nbsp;</strong>and<strong> <a href="http://www.powerpivotpro.com/2011/11/why-powerpivot-is-better-fed-from-a-database-pt2/">continued here</a>.</strong></p>
<p>But hey, not everyone has a database rapid-response team at their disposal <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-sadsmile" alt="Sad smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/wlEmoticon-sadsmile1.png"></p>
<p>So questions like this one come up a lot on the forums, reminding me of my blind spot:</p>
<p>You have two tables of data.&nbsp; In one, you have a list of your clients and their effective discount rate during particular date ranges – marked by a start and an end date.&nbsp; If the End date is blank, that discount rate is assumed to still be active.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image15.png"><img style="background-image: none; border-right-width: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb14.png" width="466" height="410"></a></p>
<p align="center"><strong>Rates Table:&nbsp; Discount Rate per Client, <br />Over Distinct Date Ranges (Start and End Effective Date)</strong></p>
<p>Then there’s a second table, listing Clients and the days that you called each of them:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image16.png"><img style="background-image: none; border-right-width: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Multiple Clients, and Multiple Calls to Each Client in PowerPivot" border="0" alt="Multiple Clients, and Multiple Calls to Each Client in PowerPivot" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb15.png" width="294" height="345"></a></p>
<p align="center"><strong>Calls Table:&nbsp; Multiple Clients, and Multiple Calls to Each Client</strong></p>
<h3>Desired Result</h3>
<p>You want to add a calculated column to that Calls table which contains that client’s effective discount rate on the date of the call:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image17.png"><img style="background-image: none; border-right-width: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Calc Column in PowerPivot Looking Up a Value Based on Date Ranges in Another Table" border="0" alt="Calc Column in PowerPivot Looking Up a Value Based on Date Ranges in Another Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb16.png" width="449" height="306"></a></p>
<p align="center"><strong>We Want to Add the Highlighted Calc Column – What’s the Formula?</strong></p>
<p>So… what’s the formula?</p>
<p><font size="3" face="Courier New">=CALCULATE(AVERAGE(Rates[Rate]), <br />&nbsp;&nbsp; FILTER(Rates, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rates[Start]&lt;=Calls[ContactDate] &amp;&amp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rates[EffectiveEnd] &gt;= Calls[ContactDate] &amp;&amp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rates[Client]=Calls[Client]<br />&nbsp;&nbsp; )<br />)</font></p>
<h3>Hey, That’s a Lot Like a Measure!</h3>
<p>Yeah, it IS a lot like a measure.&nbsp; It uses <strong><a href="http://www.powerpivotpro.com/2009/12/powerpivot-dax-calculate-is-a-supercharged-sumif/">CALCULATE, the wonder function</a></strong>. </p>
<p>But in this case, we’re just using CALCULATE to apply filters in our calculated column.</p>
<p>Works basically the same way, though.&nbsp; The three clauses in the FILTER() function are all AND’d together using the &amp;&amp; operator, so that only rows from the Rates table meeting the following three criteria are “kept” and then “fed” to the AVERAGE function:</p>
<ol>
<li>The Start date in the rates table must be prior to (or equal to) the Contact Date in the Calls table.
<li>The End date in the rates table must be after (or equal to) the Contact Date in the Calls table.
<li>The Client ID in the rates table must match the Client ID in the Calls table </li>
</ol>
<p><strong>Note for those who desire deeper understanding:</strong>&nbsp; The biggest difference between this calc column formula and a similar formula we’d have to write in a measure is that in a measure, we’d have to use the <strong><a href="http://www.powerpivotpro.com/2011/03/the-magic-of-ifvalues/">VALUES()</a></strong> function wrapped around the right hand side of the criteria – VALUES(Calls[ContactDate]) rather than just Calls[ContactDate]).&nbsp; And we’d have to “protect” those VALUES functions with an IF(COUNTROWS()) since you can’t use VALUES() as part of an “=” test, <strong><a href="http://www.powerpivotpro.com/2011/03/the-magic-of-ifvalues/">except when there is only one value returned</a></strong>, or maybe use MAX() instead of VALUES().&nbsp; The point is that in a calc column, we DO have a current row in the table, so we don’t need the wrapper function like we do in a measure.</p>
<h3>What’s that EffectiveEndDate column?</h3>
<p>Yeah I sneaked that one in.&nbsp; It’s another calc column I added to the Rates table:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image18.png"><img style="background-image: none; border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb17.png" width="626" height="423"></a></p>
<p>You can see its formula in the formula bar in the image above.&nbsp; I just wanted to put a non-blank value in whenever End was blank.&nbsp; You could hard-code a date in there if you wanted, or use TODAY() and a much bigger number than 365.&nbsp; I just figured that setting a date one year in the future from today is good.&nbsp; Keep in mind though that TODAY() will only be re-evaluated when you refresh your data or force a re-calc.</p>
<h3>Is There a Relationship Between Those Two Tables?</h3>
<p>No, there is not.&nbsp; Neat huh?&nbsp; And really, there couldn’t be anyway – each Client ID appears more than once in each table, and PowerPivot doesn’t handle relationships on “many to many” like that.&nbsp; The date columns are even less “relationship friendly” since they don’t match up at all, and are based on ranges in one table and single dates in the other.</p>
<h3>Download the Workbook</h3>
<p>I’m trying to do this more often, especially with the forum questions.</p>
<p align="center"><strong><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/EffectiveClientRatesByDate.xlsx" target="_blank"><font size="3">Download the workbook here</font></a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/02/lookups-based-on-date-ranges/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tracking Performance After an Event or Treatment</title>
		<link>http://www.powerpivotpro.com/2012/02/tracking-performance-after-an-event-or-treatment/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tracking-performance-after-an-event-or-treatment</link>
		<comments>http://www.powerpivotpro.com/2012/02/tracking-performance-after-an-event-or-treatment/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 17:43:37 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[DAX]]></category>
		<category><![CDATA[Medical/Scientific]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3715</guid>
		<description><![CDATA[&#160; “…then they start thinking that, ‘where there’s smoke there’s fire’ logic…” Continuing the Impromptu Series of Simple Real World Examples The Mr. Excel PowerPivot Forum has inspired me to change gears a little bit and focus more time on simple techniques that don’t break the DAX Spicy Scale while still being very useful, everyday [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br /><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="Jackie Brown - A Tarantino Movie I Need to Revisit Soon" border="0" alt="Jackie Brown - A Tarantino Movie I Need to Revisit Soon" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb.png" width="479" height="252"></a></p>
<p align="center"><strong>“…then they start thinking that, ‘where there’s smoke there’s fire’ logic…”</strong></p>
<h3>Continuing the Impromptu Series of Simple Real World Examples</h3>
<p>The <strong><a href="http://www.mrexcel.com/forum/forumdisplay.php?f=29" target="_blank">Mr. Excel PowerPivot Forum</a></strong> has inspired me to change gears a little bit and focus more time on simple techniques that don’t break the <strong><a href="http://www.powerpivotpro.com/2010/11/learning-dax-measures-the-spicy-function-scale/">DAX Spicy Scale</a></strong> while still being very useful, everyday stuff. I sometimes take this stuff for granted and end up looking for topics that are much more “clever” when in reality we all can use a good dose (or two, or ten) of basic useful examples.</p>
<h3>Medical Treatments – Are They Effective?&nbsp; Counterproductive?</h3>
<p>A user over at the forum named “Mirknin” posted<strong> <a href="http://www.mrexcel.com/forum/showthread.php?t=609643" target="_blank">the following question</a></strong>:</p>
<blockquote><p>I have a relatively simple data set where each row represents a week, each week has a number of data columns. Occassionally, however, we have treatments and I set up Excel with a column where the treatment is recorded as 1 &#8211; i.e. a treatment occurred that week, otherwise the cells are left blank.</p>
<p>I AddColumn in PowerPivot to generate a unique identifier (through the usual ampersand formula) to represent whether a treatment occurred in a specific week. Using the Slicer, I can PivotTable to see the data from the row where the treatment took place because all this info is related to that week, but seeing the data for following four weeks would let me see whether the treatment had made an effect.</p>
<p>I guess my query is whether the Slicer can be modified in such a way as to report the row it&#8217;s associated with plus subsequent rows&#8230;</p>
</blockquote>
<h3>Data Set:&nbsp; Let’s Use Trees Rather than People <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/wlEmoticon-smile.png"></h3>
<p>When I was manufacturing sample data for this I got a bit squeamish about it.&nbsp; Not for the obvious reasons though – I’ll explain at the end of the post.&nbsp; But for now, just know that we’re going to work with Trees, like in a Botany lab, and some experimental treatment they are receiving.</p>
<p>We have a calendar of treatments – a list of dates and Yes/No for each:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image1.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb1.png" width="212" height="345"></a></p>
<p align="center"><strong>Calendar of Treatments</strong></p>
<p>And then a table of health readings taken for various trees in the lab on specific dates:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image2.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb2.png" width="262" height="345"></a></p>
<p align="center"><strong>Tree Health Measurements</strong></p>
<h3 align="left">Normal Slicer Function Across Relationships</h3>
<p align="left">Notice that the two tables have the little “relationship” icons on the Date column?&nbsp; These two tables are related on that column.&nbsp; So if I write an “average health” measure and put the Yes/No treatment field on a slicer, I get:</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image3.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb3.png" width="375" height="110"></a></p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image4.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb4.png" width="374" height="119"></a></p>
<p>But if I put Date on rows, we’ll see that all I am “getting” in my health scores is the health of the tree on the day the treatment was applied:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image5.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb5.png" width="460" height="330"></a></p>
<h3>But I Want the Health Scores Over the Two Days AFTER Treatment!</h3>
<p>I want to track a range of dates after a treatment is applied, so I need to do something different here.</p>
<p>What I need is a new column in the TreatmentCalendar table:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb6.png" width="322" height="508"></a></p>
<p>If I use THAT column as a slicer, or even better, put it on rows of the pivot, I get what I want:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb7.png" width="414" height="158"></a></p>
<p>Hey, check it out!&nbsp; Trees are doing a little bit better in the two days after they receive treatment!&nbsp; (That’s lucky, since this sample data was created using RANDBETWEEN).</p>
<h3>But how did I build that “Recently Treated” Calculated Column?</h3>
<p>Did I say up front that this was going to be LOW on the <strong><a href="http://www.powerpivotpro.com/2010/11/learning-dax-measures-the-spicy-function-scale/">DAX Spicy Scale</a></strong>?&nbsp; Hmm.</p>
<p>First let me repeat a longstanding recommendation:&nbsp; if you are using a database as your data source for PowerPivot, you should seriously consider having this calculated column generated in the database and NOT in PowerPivot.&nbsp; <strong><a href="http://www.powerpivotpro.com/2011/11/why-powerpivot-is-better-fed-from-a-database-pt2/">There are multiple benefits of that</a></strong>, as long as it’s an option.</p>
<p>If it’s not an option, you still have two choices.&nbsp; For something relatively quick and dirty, you can do the calc column in Excel and just paste an entirely new TreatmentSchedule table into PowerPivot.</p>
<p>But for larger data sets, or cases where you can’t have that manual intervention step every time you get new data, you’re gonna have to write the calc column in PowerPivot.</p>
<p>And since PowerPivot lacks A1-style reference, and this calc column has to look at rows other than just the current row in order to get its answer, you have to use the dreaded EARLIER function.</p>
<h3>Primer:&nbsp;&nbsp; Simple Use of the EARLIER Function</h3>
<p>Before we do something advanced with EARLIER, let’s cover the basic usage first:</p>
<p>Say I have the following VERY simple table like this:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image8.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb8.png" width="299" height="206"></a></p>
<p>And I want to add a third column that is the total for each customer:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image9.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb9.png" width="438" height="156"></a></p>
<p>How do I do that?</p>
<p>The calc column formula for that third column is this:</p>
<p><font size="3" face="Courier New">=CALCULATE(SUM([Amt]), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILTER(ALL(&#8216;Table&#8217;), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8216;Table&#8217;[Customer]=EARLIER(&#8216;Table&#8217;[Customer])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</font></p>
<p>Explaining EARLIER() in depth may be its own post.&nbsp; Yeah.&nbsp; This was probably the LAST function I learned to use.&nbsp; It’s an ongoing joke between me and the Italians actually.</p>
<p>Here’s the Formula for the RecentTreatment Yes/No Column</p>
<p>With that background in mind, here is the formula for the Yes/No column.&nbsp; I actually did it in two columns:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb10.png" width="520" height="303"></a></p>
<p>That 1/0 column is the tricky one.&nbsp; The Yes/No column is just a “cosmetic” column built using IF.</p>
<p>Here’s the 1/0 formula:</p>
<p><font size="3" face="Courier New">=CALCULATE(COUNTROWS(TreatmentCalendar), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TreatmentCalendar[IsTreatmentDay]=&#8221;Yes&#8221;,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILTER(ALL(TreatmentCalendar), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TreatmentCalendar[Date] &lt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EARLIER(TreatmentCalendar[Date]) <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp;&amp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TreatmentCalendar[Date] &gt;= <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EARLIER(TreatmentCalendar[Date])-2))</font></p>
<p>Easy right? <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/wlEmoticon-smile.png"></p>
<h3>I Promise to Come Back and Explain This!</h3>
<p>EARLIER isn’t all that bad really and neither is the formula above.&nbsp; But it definitely feels a lot harder than an Excel pro wants it to be.&nbsp; Given the length of this post however I think I’ll do that next time.</p>
<h3>Calling Marco and Alberto!</h3>
<p>There are a couple of obvious questions here that my simplified example just outright skipped:</p>
<ol>
<li>What if I have more than one kind of treatment?</li>
<li>What if not all “patients” receive the same treatment, and/or on different days?</li>
<li>Can I use a slicer to control how “wide” the range of dates is rather than hardcoding 2 into my formulas?</li>
</ol>
<p>The fact that I was dodging those problems in this post is why I was squeamish about using people as the example rather than trees.&nbsp; And all three of those make this problem a lot harder.</p>
<p>And what do we do when we hit a problem that goes beyond the powers of mortal Excel Pros?&nbsp; We throw up the <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-two/">Boot Signal</a></strong> of course:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/02/image_thumb11.png" width="444" height="345"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/02/tracking-performance-after-an-event-or-treatment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comparing scientific and other data across trials</title>
		<link>http://www.powerpivotpro.com/2012/01/comparing-scientific-and-other-data-across-trials/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=comparing-scientific-and-other-data-across-trials</link>
		<comments>http://www.powerpivotpro.com/2012/01/comparing-scientific-and-other-data-across-trials/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 05:56:00 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[Custom Calendars]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Slicers]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3683</guid>
		<description><![CDATA[Enjoying the new forum! I’ve been spending some time on the Mr. Excel PowerPivot forum over the past few days and I must say I am enjoying the experience.&#160; The blog is essentially a one-way form of communication, given that far less than 1% of views result in comments. But a forum!&#160; Aha!&#160; That is [...]]]></description>
			<content:encoded><![CDATA[<h3>Enjoying the new forum!</h3>
<p>I’ve been spending some time on the <strong><a href="http://www.mrexcel.com/forum/forumdisplay.php?f=29" target="_blank">Mr. Excel PowerPivot forum</a></strong> over the past few days and I must say I am enjoying the experience.&nbsp; The blog is essentially a one-way form of communication, given that far less than 1% of views result in comments.</p>
<p>But a forum!&nbsp; Aha!&nbsp; That is different!&nbsp; I encourage you to head over there and drop a question, or maybe even try your hand at answering a question or two when they pop up.</p>
<h3>Comparison Across Trials:&nbsp; A Simple and Useful Example</h3>
<p>Here’s one that I particularly liked because it’s practical and ultimately pretty simple on the <strong><a href="http://www.powerpivotpro.com/2010/11/learning-dax-measures-the-spicy-function-scale/">DAX Spicy Scale</a></strong> after a few posts of <strong><a href="http://www.powerpivotpro.com/2012/01/prepayments-deferred-revenue/">higher complexity</a></strong> (but also extreme utility).&nbsp; </p>
<p>A user over there on the forum named “TopDown” asked a question that I will paraphrase here.&nbsp; Imagine you have a dataset like this:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image32.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="Scientific Trial Data in PowerPivot" border="0" alt="Scientific Trial Data in PowerPivot" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb26.png" width="424" height="368"></a></p>
<p align="center"><strong>Measurements Table:&nbsp; A Series of Measurements Loaded into PowerPivot</strong></p>
<p>Basically you have a set of sensors (111 through 115 in this data) and you take a set of measurements at each sensor (temperature and pressure in this example).&nbsp; Then you repeat the measurements over multiple experiments – trials 1, 2, 3, 4, etc.</p>
<p>Topdown had a few questions:</p>
<ol>
<li><strong>How do I compare the results of each trial back to the first trial?</strong>&nbsp; Absolute difference versus trial #1 and percent difference versus trial 1.</li>
<li><strong>Do I have to create calculated columns</strong> for the absolute and percent difference for each measurement like temperature?&nbsp; (Topdown said he has MANY more than two measurements)</li>
<li><strong>And if the answer to 2 is “yes,” then how is PowerPivot useful?</strong>&nbsp; Once I have the calc columns, I can create this in a normal pivot.</li>
</ol>
<p>I think intuitively, Topdown sensed that this is a great place to use PowerPivot, and just couldn’t put his finger on the how.&nbsp; He was right.&nbsp; And I really liked this problem because it is so different from the sorts of problems I work on most of the time.</p>
<h3>Solution #1:&nbsp; Nothing Fancy</h3>
<p>Hey, if you ALWAYS want trial #1 to be the baseline, this is pretty easy.&nbsp; Let’s focus on Temperature for a moment, with the understanding that Pressure will be solved the same way.</p>
<p>First we create a basic measure, AvgTemp:</p>
<p><font size="3" face="Courier New">[AvgTemp] = AVERAGE(Measurements[Temperature])</font></p>
<p>Then we create a version of that measure that ALWAYS returns the value for Trial 1:</p>
<p><font size="3" face="Courier New">[Trial1Temp] = <br />CALCULATE([AvgTemp], Measurements[Trial Number]=1)</font></p>
<p>Put both of those on a pivot with Trial Number on rows:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image33.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb27.png" width="242" height="144"></a></p>
<p>The AvgTemp measure respects the Trial Number filter on rows, just like normal measures do.&nbsp; But the Trial1Temp measure, by virtue of CALCULATE(), overrides that filter and sets it to Trial 1.&nbsp; The only place the two measures “agree” is for Trial 1, as expected.</p>
<p>A couple of quick subtraction and division measures follow:</p>
<p><font size="3" face="Courier New">[Delta Temp] = [AvgTemp]-[Trial1Temp]</font></p>
<p><font size="3" face="Courier New">[Pct Change Temp] = [DeltaTemp]/[Trial1Temp]</font></p>
<p>Yielding:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image34.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb28.png" width="473" height="178"></a></p>
<p>Again, that first row (Trial 1) is pretty useless, but the others are doing what we expect.&nbsp; If that’s distracting, we can filter the pivot to NOT display Trial 1, or we can put Trial on a slicer.</p>
<p><strong>No calc columns required.&nbsp; You just can’t do this in “normal” Excel.</strong></p>
<p>We can stop here and have a quite useful solution, but let’s get just a bit fancier <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/wlEmoticon-smile6.png"></p>
<h3>Solution #2:&nbsp; Let the report consumer choose which trials to compare!</h3>
<p>Folks, I am addicted, yes, ADDICTED to what I call “disconnected slicer tables.”&nbsp; What do I mean by that?&nbsp; I mean, tables that I import into PowerPivot for the sole purpose of parameterization.&nbsp; Let the report consumer make a selection, I “harvest” that selection via a simple formula, and then I feed that parameter into my other measures.</p>
<p>I call these tables “disconnected” because I do NOT create relationships between them and the other tables – they are islands.</p>
<p>Here’s one I just pasted into the model.&nbsp; Note that TrialSlicer2 is identical.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image35.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb29.png" width="324" height="248"></a></p>
<p align="center"><strong>TrialSlicer1 Disconnected Slicer Table <br />(TrialSlicer2 Table is IDENTICAL)</strong></p>
<p>Put both of these new single column tables on slicers and they have ZERO impact on my pivot, since there are no relationships:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image36.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb30.png" width="629" height="260"></a></p>
<p><strong>No matter what I select on those slicers, [AvgTemp] keeps returning 50.65,</strong> because there is no relationship to the Measurements table.&nbsp; The field list is warning me about that, but I don’t want to create one.</p>
<p><strong>Instead, I write measures to “harvest” the user’s selections on those slicers</strong>, so that I can use them as parameters:</p>
<p><font size="3" face="Courier New">[SelectedTrial1] = <br />IF(COUNTROWS(VALUES(TrialSlicer1[Compare To Trial]))&gt;1,BLANK(),<br />&nbsp;&nbsp;&nbsp; MAX(TrialSlicer1[Compare To Trial]))</font></p>
<p><font size="3" face="Courier New">[SelectedTrial2] = <br />IF(COUNTROWS(VALUES(TrialSlicer2[Compare To Trial]))&gt;1,BLANK(),<br />&nbsp;&nbsp; MAX(TrialSlicer2[Compare To Trial]))</font>
<p>The measures are identical except for the tables they reference, and which tables I “anchor” them to in the field list.&nbsp; The results look like:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image37.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb31.png" width="611" height="192"></a></p>
<p>OK, now that I have those two parameter measures, I can modify the [Trial1Temp] measure from above to no longer be “hard-coded” to Trial 1.&nbsp; Now I can make it variable by parameterizing it using [SelectedTrial1]:</p>
<p><font size="3" face="Courier New">[Trial1Temp] = <br />CALCULATE([AvgTemp],<br />&nbsp;&nbsp; FILTER(Measurements, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Measurements[Trial Number]=[SelectedTrial1]<br />&nbsp;&nbsp; )<br />)</font></p>
<p>Note that I only have to use FILTER() inside the CALCULATE simply because the “normal” parameters to calculate will NOT accept a measure name on the right side of the equals sign.</p>
<p>This new measure responds nicely to the selections made on the first slicer, whereas AvgTemp keeps ignoring it as always:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image38.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb32.png" width="388" height="169"></a></p>
<p>Now I can write a new [TrialXTemp] measure that is exactly the same as Trial1Temp except that it respects [SelectedTrial2] instead of [SelectedTrial1].&nbsp; Update my Delta and Pct Delta measures and now I have a completely interactive pivot:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image39.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb33.png" width="465" height="197"></a></p>
<p>Neat huh?&nbsp; And still pretty simple. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/wlEmoticon-smile6.png"></p>
<h3>Download the workbook, more variations, etc.</h3>
<p align="center"><strong><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/scientific-trials.xlsx"><font size="3">Download the workbook here</font></a></strong></p>
<p>And for another example of disconnected slicer tables, <strong><a href="http://www.powerpivotpro.com/2011/04/ab-campaign-analysis-with-start-end-date-slicers/">see here</a></strong>.</p>
<p>And naturally, if you wanted to write a measure that automatically returns the delta between trial N versus trial N-1, you can always use the <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-one/">Greatest Formula in the World</a></strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/comparing-scientific-and-other-data-across-trials/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mini Post #3:  Measures Can Return Text!</title>
		<link>http://www.powerpivotpro.com/2012/01/mini-post-3-measures-can-return-text/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mini-post-3-measures-can-return-text</link>
		<comments>http://www.powerpivotpro.com/2012/01/mini-post-3-measures-can-return-text/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 16:51:32 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[DAX]]></category>
		<category><![CDATA[Quick Tips & Tricks]]></category>
		<category><![CDATA[Usability and Appearance]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3663</guid>
		<description><![CDATA[&#160; Yes, That IS a Measure Third and Final Mini-Post for Today Got a question from a friend yesterday that made me realize I should share this:&#160; in PowerPivot, your formulas do NOT have to return numbers.&#160; As I’ve shown several times, they can return dates, but they can also return just plain and simple [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br /><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image31.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb25.png" width="536" height="522"></a></p>
<p align="center"><strong><font size="2">Yes, That IS a Measure</font></strong></p>
<h3>Third and Final Mini-Post for Today</h3>
<p>Got a question from a friend yesterday that made me realize I should share this:&nbsp; in PowerPivot, your formulas do NOT have to return numbers.&nbsp; As I’ve shown several times, they can return dates, but they can also return just plain and simple text.</p>
<p>For instance, check out the formula for that Trend measure above:</p>
<p><font size="3" face="Courier New">[Trend] = IF([$ - Sales] &gt; [$ - Sales YAG], &#8220;Up&#8221;, &#8220;Down&#8221;)</font></p>
<p>[$ – Sales] and [$ – Sales YAG] are both measures (“current sales” and “sales year ago.”)&nbsp; So this IF() is 100% dynamic and responds to whatever fields and filtering/slicing you’ve done on your pivot!&nbsp; If sales have gone up since last year, it returns “Up,” otherwise it returns “Down.”</p>
<p>One of those cool little tricks that comes in handy from time to time <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/wlEmoticon-smile5.png"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/mini-post-3-measures-can-return-text/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Prepayments &amp; Deferred Revenue</title>
		<link>http://www.powerpivotpro.com/2012/01/prepayments-deferred-revenue/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prepayments-deferred-revenue</link>
		<comments>http://www.powerpivotpro.com/2012/01/prepayments-deferred-revenue/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 05:10:00 +0000</pubDate>
		<dc:creator>David Churchward</dc:creator>
				<category><![CDATA[Accounting/Financial Techniques]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Accounting and Finance Techniques]]></category>
		<category><![CDATA[BI]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[PowerPivot]]></category>
		<category><![CDATA[SUMX]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3532</guid>
		<description><![CDATA[&#160; Guest Post by David Churchward&#160; You’ll often hear us Accountants referring to things like adjusting for timing differences or prepaying costs or deferring revenue.&#160; This is often interpreted as &#8220;massaging the numbers&#8221;, but, believe me, there is a very reasonable theory behind it.&#160; These sort of adjustments can be made for a number of [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><em>Guest Post by </em><strong><a href="http://linkd.in/pNwvk4" target="_blank">David Churchward</a>&nbsp;</strong></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Deferred-Revenue-Layout-Example.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments &amp; Deferred Revenue Layout Example" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Deferred-Revenue-Layout-Example_thumb.jpg" width="642" height="295"></a></p>
<p>You’ll often hear us Accountants referring to things like <strong>adjusting for timing differences </strong>or <strong>prepaying costs </strong>or <strong>deferring revenue</strong>.&nbsp; This is often interpreted as &#8220;massaging the numbers&#8221;, but, believe me, there is a very reasonable theory behind it.&nbsp; These sort of adjustments can be made for a number of reasons, but the main underlying concept is that adjustments have to be made to ensure that the transaction is reflected in the period to which it relates.</p>
<p>In this post, I’ll explain how prepayments and revenue deferrals work together with the DAX measures that drive these calculations.</p>
<h3>What are Timing Differences?</h3>
<p>It’s worthwhile just taking the time to understand what we’re trying to do here.&nbsp; Take, for example, a support contract that you bill to your customer in advance for 12 months.&nbsp; You invoice the customer in advance and the customer duly pays.&nbsp; However, as per accounting principles, you have to reflect the fact that the invoice relates to 12 months worth of support.&nbsp; In it’s simplest sense, your Profit and Loss should therefore see 1/12th of that revenue in each reporting month.&nbsp; Since the invoice is for a full 12 months, we have to create transactions to defer the element that relates to future periods, entering the balance onto the Balance Sheet.</p>
<p>As a quick example of the calculation, at the end of the first month to which the support contract relates, you would defer 11/12ths of the invoice value:</p>
<p><strong>Deferral Value = Invoice Value * (Number of Future Months / Total Months on Invoice)</strong></p>
<p>We would therefore see 1/12th of the invoice value on our Profit &amp; Loss and the remaining 11/12ths would be sat on our balance sheet.</p>
<p>Referring to Prepayments separately from Deferred Revenue (or Deferred Costs) for that matter is simply a matter of terminology.&nbsp; The underlying concept of the calculation is the same.&nbsp; I consider everything to be a Prepayment in this sense.&nbsp; The only difference is where the transactions sit in the Profit &amp; Loss and Balance Sheet statements.</p>
<p><strong>Note – Accountants may defer revenue or costs for other reasons.&nbsp; This post is simply a calculation to reflect the timing difference adjustment.</strong></p>
<h3>Days or Months</h3>
<p>In the simplified example above, I’ve used a monthly concept that allows for a simple allocation of the transaction value to the Profit &amp; Loss in equal monthly values.&nbsp; However, as we know, the number of days in each month can differ.&nbsp; For this calculation to be more accurate, we should pro-rata the calculation based on the number of days in that month.</p>
<p>The DAX measures that I show in this post will allow for selection of Monthly Deferral / Prepay or Daily Deferral / Prepay.&nbsp; Which you use depends on your accounting policy.</p>
<h3>Data Structure</h3>
<p>My data structure is as follows:</p>
<h4>Fact Table (Prepayments)</h4>
<p>I have a core fact table which contains all transactions that require a prepayment or deferred revenue adjustment.&nbsp; I have called this table <strong>Prepayments</strong>.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Fact-Table.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Fact Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Fact-Table_thumb.jpg" width="642" height="109"></a></p>
<p>The key elements to this table are as follows:</p>
<p><strong>Date – </strong>This is the transaction date of the invoice posting</p>
<p><strong>Nominal_PandL – </strong>This is the Profit &amp; Loss Nominal Ledger account that the invoice was posted to</p>
<p><strong>Nominal_Prepay_BS – </strong>This is the Balance Sheet Nominal Ledger account where the prepayment or deferral will be posted to.</p>
<p><strong>Start / End – </strong>These are the start and end dates of the transaction.&nbsp; If the invoice relates to a period from 1st Jan 2012 to 31st Dec 2012 then these dates would be 01/01/2012 and 31/12/2012 respectively.</p>
<p><strong>Method – </strong>This is either MONTH or DAY depending on the level of granularity that you want your calculation to be calculated at.</p>
<p><strong>PandL_Values – </strong>This is the total value of the invoice charge.</p>
<p><strong>Prepay_Start / Prepay_End – </strong>I’ll come onto these alternative dates shortly.&nbsp; In brief, these exist because your prepayment timeframe may differ from the strict dates to which the invoice relates.</p>
<h4>Days Table</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Days-Table.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Days Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Days-Table_thumb.jpg" width="447" height="126"></a></p>
<p>This table holds a sequential, unbroken list of dates (Date) together with associated attributes including <strong>Month End Date</strong>, <strong>Previous Month End Date</strong>, <strong>Month Start Date</strong> and <strong>Next Month Start Date</strong>.&nbsp; These attributes become relevant in our measures and, whilst these can be calculated at run time, it’s easier to take care of them this way.&nbsp; The purest would be correct in suggesting that there’s a potential performance impact, but dealing with these aspects in our measure may confuse the issue for now!</p>
<h4>Months Table</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Months-Table.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Months Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Months-Table_thumb.jpg" width="360" height="103"></a></p>
<p>Similar to the Days table, this table holds a collection of attributes relevant at the month level including <strong>Month End Date</strong>, <strong>Previous Month End Date</strong>, <strong>Month Start Date</strong> and <strong>Next Month Start Date</strong>.</p>
<h4>Start Dates Table</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Start-Dates-Table.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Start Dates Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Start-Dates-Table_thumb.jpg" width="280" height="176"></a></p>
<p>This is another sequential list of dates which is joined to the <strong>Start</strong> field on the <strong>Prepayments</strong> table.&nbsp; I’ll come on to the <strong>PrepayStartdate</strong> field shortly.</p>
<h4>End Dates Table</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-End-Dates-Table.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments End Dates Table" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-End-Dates-Table_thumb.jpg" width="182" height="134"></a></p>
<p>This is another sequential list of dates which is joined to the <strong>End </strong>field on the <strong>Prepayments </strong>table.&nbsp; You’ll notice the absence of a third field which, again, I’ll come on to.</p>
<h4>Table Relationships</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Table-Relationships.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Table Relationships" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Table-Relationships_thumb.jpg" width="404" height="268"></a></p>
<p>The only relationships that exist are between the <strong>Prepayments</strong> table and the <strong>Start_Dates </strong>and <strong>End_Dates </strong>tables.</p>
<h3></h3>
<h3>Dates That Span Periods</h3>
<p>A charge period can be anything.&nbsp; In it’s simplest form, it would be for complete months starting on the first day of a month and ending on the last day of a month.&nbsp; However, things are never that simple.&nbsp; Unfortunately, you could get a charge that is for 3 months from 14th Jan 2012 to 13th Apr 2012 as an example.&nbsp; The time between these two dates is indeed 3 months, but the charge covers 4 discrete calendar months.</p>
<p>If you’re using a <strong>Days</strong> method of apportionment, this isn’t a problem.&nbsp; However, if you’re apportioning on the basis of months, you have 3 options in this example:</p>
<ol>
<li>Take the 3 equal months charges as Feb, Mar and Apr
<li>Take the 3 equal months charges as Jan, Feb and Mar
<li>Take equal monthly charges for Feb and Mar with a pro-rata charge for Jan and Apr. </li>
</ol>
<p>In truth, if you’re going to even attempt option 3, you would probably be better off jumping straight for the <strong>Days</strong> apportionment and circumvent the problem!&nbsp; Options 1 and 2 depend on accounting policy and president.&nbsp; The prudent option would probably be to go for option 2 for costs (taking them as early as possible) and option 1 for Revenue (taking later rather than earlier).&nbsp; On the basis of consistency, I feel it’s best to prescribe this in your accounting policies and then use the same method for everything.&nbsp; Having said that, the best option is almost certainly to take a <strong>Days</strong> approach.</p>
<p>For the purpose of this post, I’m going to use option 1.&nbsp; This means that I’ll translate any start date that isn’t the first day of the month to the first day of next month.&nbsp; I create two calculated fields on my <strong>Prepayments</strong> table as follows:</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepay_Start</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=IF(Prepayments[Method]=&#8221;MONTH&#8221;,RELATED(Start_Dates[PrepayStartdate]),Prepayments[Start])</span></span></span></p>
<p>&nbsp;</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepay_End</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=IF(Prepayments[Method]=&#8221;MONTH&#8221;,RELATED(End_Dates[MonthEndDate]),Prepayments[End])</span></span></span></p>
<p>These measures retrieve an alternative date from the Start_Dates and End_Dates table.&nbsp; For any <strong>mid-month </strong>dates, this table holds a <strong>PrepayStartdate</strong> of the first of the next month.</p>
<h3>The Months Approach</h3>
<p>Firstly, let’s just remember our simplified equation to give us the deferral value:</p>
<p><strong>Deferral Value = Invoice Value * (Number of Future Months / Total Months on Invoice)</strong></p>
<p>And now we’ll jump straight into the DAX</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Month_Prepayment</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=IF(COUNTROWS(VALUES(Months[MonthEndDate]))=1,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">IF(LASTDATE(VALUES(Prepayments[Prepay_Start]))&lt;LASTDATE(VALUES(Months[MonthEndDate]))</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&amp;&amp;LASTDATE(VALUES(Prepayments[Prepay_End]))&gt;LASTDATE(VALUES(Months[MonthEndDate])),</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">CALCULATE(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">SUMX(Prepayments,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[PandL_Value]</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">*(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">(CALCULATE(COUNTROWS(Months),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Months[MonthEndDate],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(VALUES(Months[MonthEndDate])),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(End_Dates[MonthEndDate])</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )-1</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp; )/</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">CALCULATE(COUNTROWS(Months),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Months[MonthEndDate],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(Start_Dates[PrepayStartdate]),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(End_Dates[MonthEndDate])</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Method]=&#8221;Month&#8221;</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">)</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">)</span></span></span></p>
<p>The first two <strong>IF statements</strong> in this measure calculate when we want the rest of the measure to evaluate.&nbsp; We want this measure to evaluate when:</p>
<ol>
<li>The number of month end dates on our report is 1 (because anything else is likely to return an error)
<li>The prepayment start and end dates fit within the range of our report.&nbsp; This, essentially, tells the report which month end dates to display and the rest of the measure uses these dates to evaluate the correct result to display. </li>
</ol>
<p>We then use a <strong>CALCULATE</strong> statement to calculate our basic equation:</p>
<p><strong>Deferral Value = Invoice Value * (Number of Future Months / Total Months on Invoice)</strong></p>
<p><strong>Invoice Value = </strong><span style="font-size: small"><span style="font-family: courier new"><span style="color: #000000">SUMX(Prepayments,</span></span><span style="font-family: courier new"><span style="color: #000000">Prepayments[PandL_Value]</span></span></span></p>
<p><strong>Number of Future Months</strong> =</p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">*(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">(CALCULATE(COUNTROWS(Months),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Months[MonthEndDate],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(VALUES(Months[MonthEndDate])),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(End_Dates[MonthEndDate])</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )-1</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p>&nbsp;</p>
<p>This calculates the number of month values in the <strong>Months</strong> table using the <strong>COUNTROWS</strong> function that sit between the <strong>MonthEndDate</strong> on our report and the <strong>MonthEndDate</strong> of the end date of our transaction.&nbsp; I then subtract 1 to reflect that the <strong>MonthEndDate</strong> of the report is not included as it is the current reporting month.</p>
<p><strong>Total Months on Invoice</strong> =</p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">/</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">CALCULATE(COUNTROWS(Months),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Months[MonthEndDate],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(Start_Dates[PrepayStartdate]),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(End_Dates[MonthEndDate])</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp; )</span></span></span></p>
<p>Once again, I’m counting the number of entries in the <strong>Months</strong> table that sit between the start and end dates of our prepayment timeframe.</p>
<p>I then apply a filter to the <strong>CALCULATE</strong> statement to ensure that this measure is only applied to transactions where the <strong>Method </strong>is set to &#8220;MONTH&#8221;.</p>
<h4>So why do we have to use SUMX for the Invoice Value?</h4>
<p>The simple answer is that we need to <strong>conduct this equation at the transaction level of granularity and then SUM the results.&nbsp; </strong>The main reason for this is that we’re using a division calculation which is only relevant at that level and becomes confused and meaningless when aggregated.</p>
<p>In order to show this, I’ll explain a simple example of converting USD to GBP with some theoretical exchange rates:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/SUMX-Example.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="SUMX Example" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/SUMX-Example_thumb.jpg" width="197" height="85"></a></p>
<p>What are the values for X and Y?&nbsp; We obviously know that Y needs to be <strong>150</strong>, being the sum of the two GBP values.&nbsp; However, if we use <strong>SUM</strong>, we wouldn’t get that answer.&nbsp; The answer that you would get depends on how you condition your measure but you wouldn’t get an answer of 150, it’s more likely to be 150/2=75 (where <strong>MAX</strong> is used in the equation) or 250/3.5=71.42 (where <strong>SUM</strong> is used) or 250/1.75=142.86 (where <strong>SUM</strong> and <strong>AVERAGE </strong>is used).&nbsp; The correct value only comes about when you use SUMX which sums the underlying outcomes of the equation and evaluates at the granularity level of the table that you specify (in our case the base level fact table – Prepayments).</p>
<p>This is a very brief outline of a very complex and clever function.&nbsp; In short, if you want to simply add the outcome of underlying equations, SUMX is the way to go.</p>
<p>It’s worth checking out one of my favourite ever posts to start getting to grips with SUMX &#8211; <a href="http://www.powerpivotpro.com/2010/02/sumx-the-5-point-palm-exploding-fxn-technique/" target="_blank"><strong>SUMX() &#8211; The 5 point palm exploding fxn technique</strong></a>.</p>
<h3></h3>
<h3>The Days Approach</h3>
<p>This uses the same methods and concepts as the Month approach.&nbsp; The only difference is that we’re evaluating to the number of days in the relevant periods of time.</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Days_Prepayment</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=IF(COUNTROWS(VALUES(Months[MonthEndDate]))=1,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">IF(LASTDATE(VALUES(Prepayments[Prepay_Start]))&lt;LASTDATE(VALUES(Months[MonthEndDate]))</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&amp;&amp;LASTDATE(VALUES(Prepayments[Prepay_End]))&gt;LASTDATE(VALUES(Months[MonthEndDate])),</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">CALCULATE(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">SUMX(Prepayments,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[PandL_Value]</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">*(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">(CALCULATE(COUNTROWS(Days),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Days[Date],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">LASTDATE(VALUES(Months[MonthEndDate])),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Prepay_End])</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )-1</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp; )/</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">CALCULATE(COUNTROWS(Days),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">DATESBETWEEN(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Days[Date],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Prepay_Start],</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.25in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Prepay_End]</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 2.625in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">,Prepayments[Method]=&#8221;Day&#8221;</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp; )</span></span></span></p>
<h3>Prepayments Total</h3>
<p>We now have two measures to evaluate our Days Prepayments and our Months Prepayments.&nbsp; We can bring these together in one measure as follows:</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments_Total</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=SUMX(Prepayments,[Month_Prepayment]+[Days_Prepayment])</span></span></span></p>
<p>Once again, I have to use <strong>SUMX</strong> to ensure that this measure sums the total of the underlying calculations.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Without-Values-Not-Prepaying.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Without Values Not Prepaying" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Without-Values-Not-Prepaying_thumb.jpg" width="642" height="127"></a></p>
<h3>The &#8220;Values Not Prepaying&#8221;</h3>
<p>So we’ve dealt with the reducing balances associated with Monthly and Daily Prepayments and Deferred Revenues.&nbsp; However, what about a situation where the invoice charge relates to future months that haven’t yet been reached?&nbsp; For example, we receive an invoice in January that relates to April and beyond, as in the screen shot above where the last entry has a transaction date of 10th Jan but relates to a period April to October.&nbsp; In this instance, we have to prepay (or defer) the full amount of the invoice for January, February, March and April.</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Value_Not_Prepaying</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=CALCULATE</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">(</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">SUMX(Prepayments,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[PandL_Value]</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">FILTER(Prepayments,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Date]&lt;LASTDATE(VALUES(Months[MonthEndDate]))</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">FILTER(Prepayments,</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments[Prepay_Start]&gt;LASTDATE(VALUES(Months[MonthEndDate]))</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp; )</span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">&nbsp;&nbsp; )</span></span></span></p>
<p>In this measure, we once again use <strong>SUMX</strong> to ensure that we SUM the outcome of the underlying evaluations.&nbsp; However, we apply two filters to limit the selection to situations where certain criteria hold.&nbsp; This is an alternative to preceding the <strong>CALCULATE</strong> with an <strong>IF</strong> statement to conduct this evaluation first.</p>
<ol>
<li>The first filter evaluates when transaction date is less than the MonthEndDate of the report column
<li>The second filter evaluates when the Prepay_Start date is greater than the MonthEndDate of the report column. </li>
</ol>
<p>We then add this into our Prepayments_Total measure as:</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">Prepayments_Total</span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small">=SUMX(Prepayments,[Month_Prepayment]+[Days_Prepayment]+[Value_Not_Prepaying])</span></span></span></p>
<p>&nbsp;</p>
<p style="line-height: normal; margin: 0in"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Balance-Sheet-Layout.jpg"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Prepayments Balance Sheet Layout" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Prepayments-Balance-Sheet-Layout_thumb.jpg" width="642" height="127"></a></p>
<p>And there you have it.&nbsp; Our Balance Sheet layout above shows the total value of each transaction that needs to be prepaid or deferred in each month.</p>
<h3>What This Means to Accountants</h3>
<p>For those Accountants amongst you, you’ll no doubt have cottoned onto the fact that, if you’re careful, this could be your prepayments and deferred revenue reconciliations conquered.&nbsp; The process that I’ve always implemented is as follows:</p>
<ol>
<li>Ensure that all transactions are posted to the Profit and Loss in full, as if the P&amp;L was going to take the whole value in one period.
<li>Capture prepayment start and end dates on each transaction
<li>Extract the data into a PowerPivot application such as this.
<li>Refresh to give you the values that need to be prepaid (as per the above screenshot)
<li>Journal the appropriate values between the Profit and Loss and Balance Sheet on a reversing journal.
<li>Next month the previous transaction will reverse and you do the same again. </li>
</ol>
<p>By doing this, you’ve got a self reconciling Balance Sheet for Prepayments and Revenue Deferrals (and all transactions for that matter that have a straight line release – for example, you could use this for elements of Fixed Asset Depreciation but that’s a whole other post).</p>
<h3></h3>
<h3>And One More Thing</h3>
<p>You may have noticed in the first graphic that there was also a Profit &amp; Loss impact section to the report.&nbsp; I’ll come onto this in a future post but it uses similar concepts to the measures in this post.&nbsp; With this in place, you’ve got elements of a forecast P&amp;L, you’re on course for Recurring Revenue Assurance analysis and you’re putting in place the building blocks of a full Finance Business Intelligence Application that’s just dying to be exposed in SharePoint as per Rob’s post <a href="http://www.powerpivotpro.com/2012/01/in-the-browser-aesthetics-yield-a-greater-return/" target="_blank"><strong>In the Browser Aesthetics Yield a Greater Return</strong></a><strong>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/prepayments-deferred-revenue/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Data of Different Grains:  A Followup</title>
		<link>http://www.powerpivotpro.com/2012/01/data-of-different-grains-a-followup/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=data-of-different-grains-a-followup</link>
		<comments>http://www.powerpivotpro.com/2012/01/data-of-different-grains-a-followup/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 05:03:37 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[Custom Calendars]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Quick Tips & Tricks]]></category>
		<category><![CDATA[PowerPivot Power Pivot Microsoft SharePoint BI Excel Business Intelligence]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3647</guid>
		<description><![CDATA[&#160; Sales Measure Returns the Same Value for Everything:&#160; We Solved the Calendar/Periods Problem But Now We Have a Products/Category Problem Quick Recap:&#160; We Created a Separate “Periods” Table In last week’s post, I explained how PowerPivot can very easily help you solve the “Budget vs. Actuals” problem or any other problem where you have [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br /><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image18.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb14.png" width="514" height="451"></a></p>
<p align="center"><strong>Sales Measure Returns the Same Value for Everything:&nbsp; We Solved the Calendar/Periods<br /> Problem But Now We Have a Products/Category Problem</strong></p>
<h3 align="left">Quick Recap:&nbsp; We Created a Separate “Periods” Table</h3>
<p align="left"><strong><a href="http://www.powerpivotpro.com/2012/01/salesbudget-integrating-data-of-different-grains/">In last week’s post</a></strong>, I explained how PowerPivot can very easily help you solve the “Budget vs. Actuals” problem or any other problem where you have data sets of different granularities that you want to compare in a single report.</p>
<p align="left">The crux of the problem in my example was that my Budget table only budgeted down to the Month level whereas my Sales table went down to the day level.</p>
<p align="left">To solve that, I created a separate table that only contained months (no sales or budget data, just months), and assigned a “PeriodID” to each month.&nbsp; (I could have just as easily called it MonthId).</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image19.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb15.png" width="429" height="288"></a></p>
<p align="center"><strong>The Newly-Created Periods Table</strong></p>
<p align="left">I then linked that PeriodID column to the PeriodID column that already existed in my Budget table:</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image20.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb16.png" width="450" height="329"></a></p>
<p align="left">And then created a new PeriodID column in my Sales table using a formula:</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image21.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb17.png" width="520" height="223"></a></p>
<p align="left">Resulting in a three-table setup that looks like this:</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image22.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb18.png" width="423" height="345"></a></p>
<p align="left">Which then allows me to use fields from that Periods table on slicers (or on rows or columns) while using measures from both Sales and Budget in the same pivot:</p>
<p align="left"><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image23.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb19.png" width="431" height="455"></a></p>
<p align="left">And that, my friends, is a very useful thing indeed.</p>
<h3 align="left">Could I have just added the PeriodID column to Sales and Stopped?</h3>
<p>This is an important question for us to stop and consider.&nbsp; Once I had a PeriodID column in both Sales and Budget, <strong>could I have skipped the creation of the Periods table and just moved on?</strong></p>
<p><strong>No.&nbsp; I could not.</strong>&nbsp; And there are two reasons.</p>
<p><strong><em>Reason #1:</em></strong>&nbsp; I can’t create a relationship between Sales and Budget.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image24.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb20.png" width="568" height="333"></a></p>
<p align="center"><strong>Each PeriodID Appears More than Once in Each Table, So You Can’t Relate <br />Sales Directly to Budget or Vice Versa</strong></p>
<p>That’s just the way relationships work.&nbsp; The matching column needs to be unique (no value appears more than once) in at least one of the two tables.&nbsp; No need to really worry about why, but if you think about how VLOOKUP works when you set the last argument to FALSE, it’s pretty similar.</p>
<p><strong><em>Reason #2:</em></strong>&nbsp; Without a relationship, PeriodID from one table doesn’t work with measures from the other.</p>
<p>Look what happens to Budget measures if I use PeriodID from the Sales table:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image25.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb21.png" width="633" height="314"></a></p>
<p align="center"><strong>PeriodID from Sales Table Results in Broken Budget Measures <br />(and a relationship warning)</strong></p>
<p>Yep, all busted.&nbsp; And if I use PeriodID from the Budget table, I’ll get good Budget numbers but the Sales numbers will be hosed instead.</p>
<p>THAT is why the third, new, separate Periods table is required.&nbsp; When I use fields from THAT table on my pivot, I can use measures from both Sales and Budget at the same time and nothing is broken.</p>
<p>So we use the Periods table as a master filter of sorts, one that can drive filters down into both Sales and Budget.</p>
<h3>“Master Filter” Table is a MUCH better description than “Bridge”</h3>
<p>I debated using a “bridge” metaphor to describe the role of the Periods table but I think that’s misleading – a bridge helps you travel from point A to point B:&nbsp; A –&gt; Bridge –&gt; B.&nbsp; That would make you think that we’re “starting” on the Sales table and “traversing” the Periods table to get to the Budget table.</p>
<p>But that’s not how it works.&nbsp; Neither Sales nor Budget is “in charge” here – neither is the starting point.&nbsp; There are two separate paths here:&nbsp; Periods –&gt; Sales, and Periods –&gt; Budget.&nbsp; The diagram drives that home:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image26.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb22.png" width="423" height="345"></a></p>
<p>So you should think of the Periods table as being “in charge” here.&nbsp; Which makes sense, since you have to use it on the pivot, and can’t use PeriodID from either Sales or Budget.</p>
<h3>Extending that Rule to Fields Other than PeriodID</h3>
<p>This is the crux of what I left out of my previous post, and it’s an important rule to drive home:</p>
<p><strong><font size="2">When you have separate data tables that cannot be combined into a single table (as is the case with Sales and Budget), you CANNOT use row/column/slicer fields from one table in a pivot with measures from the other table.&nbsp; You MUST have a separate “master filter” table, and use fields from THAT table in your pivot.</font></strong></p>
<p>So does that apply to fields other than PeriodID?&nbsp; You betcha.&nbsp; Guess what happens if you use a Product Subcategory or similar field from the Budget table in a pivot that contains a Sales measure (or vice versa)?&nbsp; Yeah, same problem as trying to use PeriodID from Sales as we did above:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image27.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb23.png" width="514" height="451"></a></p>
<p>What’s the solution?&nbsp; A separate master filter table for Products!</p>
<p>And that may be as simple as a single column:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image28.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb24.png" width="242" height="470"></a></p>
<h3>Wash, Rinse, Repeat</h3>
<p><strong>Once you have measures from two different data tables, every row/column/slicer field you use requires a separate master filter table.</strong></p>
<p>It may sound tedious but it’s actually quite quick.&nbsp; To easily create such a table <strong>you can even just use&nbsp; a pivot:</strong>&nbsp; </p>
<ol>
<li>Put the ProductSubCat field from either Sales or Budget on rows.</li>
<li>Copy/paste that column of unique values into PowerPivot as a new table.</li>
<li>Create the relationships to Sales and Budget.&nbsp;&nbsp; </li>
<li>Use fields from the newly created master filter table in your pivot.&nbsp; Done.</li>
</ol>
<p>(Better to get someone to add a new view or table to a database for you if that’s available, but copy/paste works well otherwise).</p>
<h3>Also Useful for Single Table Situations!</h3>
<p>One last point:&nbsp; even when you only have a single table of data, like Sales, it’s often still quite useful to create separate master filter tables.</p>
<p>Why is that?</p>
<p>Because when you create master filter tables, it gives you the opportunity to remove lots of columns from your “big” table.</p>
<p>Imagine a sales table that, in addition to columns like Quantity and Amount, also contains columns like CustomerID, CustomerGender, CustomerAge, CustomerAddress1, CustomerAddress2, etc.</p>
<p>If you leave CustomerID in the sales table but “move” all of the other customer columns into a separate Customer table, and then link the two tables by Customer ID, you can reduce the number of columns in your Sales table by a significant number.</p>
<p>And that can sometimes shrink your files dramatically, AND speed them up.&nbsp; <strong><a href="http://www.powerpivotpro.com/2011/08/less-columns-more-rows-more-speed/">See this post for an example</a></strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/data-of-different-grains-a-followup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sales/Budget: Integrating Data of Different &#8220;Grains&#8221;</title>
		<link>http://www.powerpivotpro.com/2012/01/salesbudget-integrating-data-of-different-grains/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=salesbudget-integrating-data-of-different-grains</link>
		<comments>http://www.powerpivotpro.com/2012/01/salesbudget-integrating-data-of-different-grains/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 16:17:58 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[Accounting/Financial Techniques]]></category>
		<category><![CDATA[Custom Calendars]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Quick Tips & Tricks]]></category>
		<category><![CDATA[PowerPivot Power Pivot Microsoft SharePoint BI Excel Business Intelligence]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3503</guid>
		<description><![CDATA[&#160; Latest Article for CIMA Insight Some of you know that I’ve been writing a series of articles for the Chartered Institute of Management Accounts, aka CIMA.&#160; Up until this point those articles have either focused on the organizational impact, the “why” of PowerPivot.&#160; Things like how it contrasts with traditional BI and traditional spreadsheets.&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br /><a href="http://www.flickr.com/photos/saz/33877971/" target="_blank"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image9.png" width="559" height="210"></a></p>
<h3>Latest Article for CIMA Insight</h3>
<p>Some of you know that I’ve been writing a series of articles for the Chartered Institute of Management Accounts, aka CIMA.&nbsp; Up until this point those articles have either focused on the organizational impact, the “why” of PowerPivot.&nbsp; Things like <strong><a href="http://www.cimaglobal.com/en-gb/Thought-leadership/Newsletters/Insight-e-magazine/Insight-2011/Insight-August-2011/Excel-extras-introducing-PowerPivot/" target="_blank">how it contrasts with traditional BI and traditional spreadsheets</a></strong>.&nbsp; How it <strong><a href="http://www.cimaglobal.com/en-gb/Thought-leadership/Newsletters/Insight-e-magazine/Insight-2011/Insight-October-2011/Excel-extras-using-PowerPivot-for-BI-projects/" target="_blank">saves costs and delivers more</a></strong>.</p>
<p>And then I started to introduce basic topics that have already been covered at length here on this blog, just simple how-to-get-started stuff.</p>
<p>But this month is the first time I wrote something for CIMA that I have not really covered here.</p>
<h3>The Problem:&nbsp; 60k Sales Rows vs. 2k Budget Rows</h3>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image10.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="PowerPivot Sales Data Very Granular Day Level" border="0" alt="PowerPivot Sales Data Very Granular Day Level" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb7.png" width="581" height="260"></a></p>
<p align="center"><strong>Sales Table with 60 Thousand Rows</strong></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image11.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="PowerPivot Budget Table Less Granular Month Level" border="0" alt="PowerPivot Budget Table Less Granular Month Level" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb8.png" width="530" height="264"></a></p>
<p align="center"><strong> Budget Table with Two Thousand Rows</strong></p>
<h3>The Desired Result:&nbsp; A Single Unified Report</h3>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image12.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="PowerPivot Report Combining Day Level Actual Sales and Month Level Budget Granularities" border="0" alt="PowerPivot Report Combining Day Level Actual Sales and Month Level Budget Granularities" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image_thumb9.png" width="475" height="502"></a></p>
<h3>The Solution</h3>
<p><a href="http://www.cimaglobal.com/en-gb/Thought-leadership/Newsletters/Insight-e-magazine/Insight-2012/Insight-January-2012/Excel-extras-January-2012/" target="_blank"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="Diagram of How to Integrate Different Granularities of Data in PowerPivot" border="0" alt="Diagram of How to Integrate Different Granularities of Data in PowerPivot" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/image13.png" width="490" height="401"></a></p>
<p>Here’s where I have simplified it a bit for the introductory audience.&nbsp; I likely have a Calendar table in a well-designed model, and that doesn’t appear in the diagram.&nbsp; I also likely have to solve for more than just Time granularity – the Budget is also likely less granular at the Product level as well.</p>
<p>But to introduce this powerful concept, I think a simple example is best so I kept it clean.</p>
<p align="center"><strong><font size="3"><a href="http://www.cimaglobal.com/en-gb/Thought-leadership/Newsletters/Insight-e-magazine/Insight-2012/Insight-January-2012/Excel-extras-January-2012/" target="_blank">Click here to read the full (short) article and see the details of how I create the linkage between the two tables.</a></font></strong></p>
<h3>Popular Topic This Month!</h3>
<p>Everyone has this on the brain this month it seems <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/wlEmoticon-smile1.png"></p>
<p>First, in the exact same issue of CIMA, there’s an article about handling <a href="http://www.cimaglobal.com/en-gb/Thought-leadership/Newsletters/Insight-e-magazine/Insight-2012/Insight-January-2012/Spreadsheet-skills-Modelling-Actual-versus-Budget/" target="_blank"><strong>Sales vs. Budget using traditional Excel</strong></a>.</p>
<p>And Marco Russo has <strong><a href="http://www.sqlbi.com/articles/budget-and-other-data-at-different-granularities-in-powerpivot/" target="_blank">written one about this same topic</a></strong> in PowerPivot and BISM Tabular.&nbsp; As usual, his approach is excellent, and quite different from what my more primitive mind conjures.</p>
<p>I didn’t even have to use the Boot Signal:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image18.png" target="_blank"><img style="margin: 0px auto; display: block; float: none" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image18.png" width="156" height="121"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/salesbudget-integrating-data-of-different-grains/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Switching Subtotals On &amp; Off Dynamically Using DAX in PowerPivot</title>
		<link>http://www.powerpivotpro.com/2012/01/switching-subtotals-on-off-dynamically-using-dax-in-powerpivot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=switching-subtotals-on-off-dynamically-using-dax-in-powerpivot</link>
		<comments>http://www.powerpivotpro.com/2012/01/switching-subtotals-on-off-dynamically-using-dax-in-powerpivot/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 11:35:30 +0000</pubDate>
		<dc:creator>David Churchward</dc:creator>
				<category><![CDATA[Accounting/Financial Techniques]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Quick Tips & Tricks]]></category>
		<category><![CDATA[BI]]></category>
		<category><![CDATA[Cash Flow Statement]]></category>
		<category><![CDATA[COUNTROWS]]></category>
		<category><![CDATA[COUNTX]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[PowerPivot]]></category>
		<category><![CDATA[Subtotals]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3409</guid>
		<description><![CDATA[Guest Post by David Churchward Subtotals on or off for a field - They’re the options that you get.  That’s probably great for a lot of situations, but I would put money on the majority of readers of this post having had a situation where they’ve asked “where’s the option to not display a subtotal [...]]]></description>
			<content:encoded><![CDATA[<p><em>Guest Post by </em><strong><a href="http://linkd.in/pNwvk4" target="_blank">David Churchward</a></strong></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-With-and-Without-Subtotals.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-With-and-Without-Subtotals_thumb.jpg" alt="Cash Flow Statement With and Without Subtotals" width="642" height="229" border="0" /></a></p>
<p><strong>Subtotals on or off for a field -</strong> They’re the options that you get.  That’s probably great for a lot of situations, but I would put money on the majority of readers of this post having had a situation where they’ve asked “<strong>where’s the option to not display a subtotal when there’s only one record being shown?</strong>”.  Frustrating isn’t it?  You end up with a load of subtotals simply repeating the same value as it’s own one subset member because one of your other report elements has a subset of data that <strong>does</strong> need subtotalling.  You can, of course, toggle the show and hide for each member, but wouldn’t it be better if it was dynamic?</p>
<p>Fortunately, DAX has the answer.  It’s not the answer that I would have hoped for because this one feels like it should be an option setting somewhere.  However, we can deliver the same functionality by writing it into our measures.</p>
<p>In this post, I’ll explain how to create a dynamic measure that works out whether a subtotal is needed and displays that subtotal accordingly.  I’ll be using the report that was created as part of the <a href="http://www.powerpivotpro.com/2011/12/cash-flow-statement-in-powerpivot/" target="_blank"><strong>Cash Flow Statement</strong></a><strong> </strong>post.</p>
<h3></h3>
<h3>The Subtotal Issue</h3>
<p>Let’s refer back to the final report that I created for the Cash Flow Statement.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Cash-Flow-Statement-With-Totals21.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2012/01/Cash-Flow-Statement-With-Totals2_thumb.jpg" alt="Cash Flow Statement With Totals2" width="642" height="423" border="0" /></a></p>
<p>In the column <strong>CF3_Name</strong>, the only subtotal that I want to see is the one on <strong>Working Capital</strong> as this is the only one that has any lower level detail.  You’ll notice that all other areas are carrying subtotals  which only serves to repeat the number above it.</p>
<h3>COUNTROWS and COUNTX</h3>
<p>In order to solve this problem, you obviously need to know how many subset elements there are that would make up your subtotal.  It would be reasonable to jump straight for <strong>COUNTROWS</strong>.  Let’s examine that quickly with a measure that we’ll call <strong>CF4_Headings_No</strong> in the hope that it will tell us how many headings are in our subset.</p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">CF4_Headings_No</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">= COUNTROWS(VALUES(CF4[CF4]))</span></span></span></span></span></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTROWS-Separate-Tables.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTROWS-Separate-Tables_thumb.jpg" alt="COUNTROWS Separate Tables" width="402" height="332" border="0" /></a></p>
<p>On the face of it, that doesn’t appear to give us what we want.  We have the same results for all headings and <strong>CF4_Name</strong> repeats all of the same headings.  The reason that this happens is because <strong>CF3_Name</strong> and <strong>CF4_Name</strong> are held on separate tables.  Although they hold relationships to the same table, PowerPivot doesn’t pre-determine which combinations of these fields exist, <strong>even at run-time</strong>.</p>
<p>So let’s look at what happens when these headings <strong>are</strong> held on the same table with the same <strong>COUNTROWS</strong> formula (but obviously changing table name etc!).</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTROWS-Same-Table.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTROWS-Same-Table_thumb.jpg" alt="COUNTROWS Same Table" width="404" height="448" border="0" /></a></p>
<p>That looks better right?  We can see all of the correct combinations of <strong>CF3_Name</strong> and <strong>CF4_Name</strong>.  On the one hand, this is good because we can distinguish the fact that Working Capital is the only element that has more than 1 subset item and therefore the only element that requires a subtotal.</p>
<p>However, there’s one big downside here.  For all other sections, we can’t distinguish between a subtotal line and a detail line.  There’s a couple more downsides here too:</p>
<ol>
<li>I have to create a table that holds all of the combinations of these headings.  This isn’t the biggest issue as I have a table called GL_Headings that holds the codes associated to these headings.  I can create a <span style="font-family: courier new"><span style="color: #000000"><strong>RELATED()</strong></span></span>measure in my PowerPivot dataset to return the heading name.  However, why bother if we don’t have to?</li>
<li>Don’t underestimate the power of the function <span style="font-family: courier new"><span style="color: #000000"><strong>COUNTROWS(VALUES(TABLE[FIELD]))</strong></span></span> returning a value of 1 which happens when headings are held as a separate table.  This opens up a whole host of functionality and it’s probably one of the most important aspects of PowerPivot in my opinion.</li>
</ol>
<h4></h4>
<h4>So, what’s the final analysis of COUNTROWS</h4>
<ol>
<li>Using COUNTROWS against a <strong>separate table with unique values for each heading </strong>gives us the means to distinguish between subtotal sections and detail sections of our report.</li>
<li>Using COUNTROWS against a <strong>combined table with heading combinations </strong>tells us the CF3 headings that carry detail where we do want to see a subtotal.</li>
</ol>
<p>I’m sure you’ve probably deduced where I’m going with this as the combination of these two elements probably tells us what we need to know to figure out whether a subtotal is required.  Unfortunately, this is not entirely true.  The problem is that the combination of these elements won’t operate in context unless the context is directly applied against the heading table (ie you put a slicer on the report for the cash flow heading elements).  What about a date slicer?  If you apply a date slicer which is a separate table, these measures won’t react.</p>
<h3></h3>
<h3>Bring on COUNTX</h3>
<p>Let’s jump straight into the DAX on this one and see what it’s doing by creating a measure called <strong>CF3_Total_Reqd</strong>.</p>
<p style="line-height: normal;margin: 0in" lang="en-US"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">CF3_Total_Reqd</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">=COUNTX(CF4,[Cash_Flow_Statement])</span></span></span></span></span></p>
<p><strong>COUNTX</strong> is analysing our CF4 table in the context of our measure <strong>[Cash_Flow_Statement]</strong> (as calculated in the <a href="http://www.powerpivotpro.com/2011/12/cash-flow-statement-in-powerpivot/" target="_blank"><strong>Cash Flow Statement</strong></a><strong> </strong>post).  The context applied to [Cash_Flow_Statement] is carried across to our <strong>COUNTX</strong> formula.  We run this against our <strong>CF4</strong> table because we want to get the number of detail heading names that carry a value in our <strong>[Cash_Flow_Statement]</strong> measure.</p>
<p>So what do we get:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTX.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTX_thumb.jpg" alt="COUNTX" width="402" height="309" border="0" /></a></p>
<p>Our <strong>CF3_Total_Reqd</strong> measure using <strong>COUNTX</strong> is telling us how many headings are used in our dataset <strong>for</strong> the <strong>MonthEndDate</strong> shown on our report.  This is exactly what we want.  What’s even more special is that if, in a particular month, our <strong>[Cash_Flow_Statement]</strong> measure only has one heading in the Working Capital section, the Working Capital Total would return a value of 1, which is a scenario when we want to switch our subtotal off.</p>
<h4>But there’s a problem</h4>
<p>Our <strong>COUNTX</strong> measure, as it stands, is returning a count where we have a heading, but it isn’t telling us when we have a valid blank entry at the <strong>CF4_Name</strong> level.  As a result, any <strong>CF3</strong> category that doesn’t carry <strong>CF4</strong> heading detail, isn’t telling us anything.  I know we have Operating Profit elements, but we’re not getting any counts returned.</p>
<p>But what if we specify the column that we’re analysing in our <strong>CF4</strong> table?  We can do this by adding in <strong>VALUES</strong> and specifying the column in our <strong>CF4</strong> table.</p>
<p style="line-height: normal;margin: 0in" lang="en-US"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">CF3_Total_Reqd</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">=COUNTX(VALUES(CF4[CF4_Name]),[Cash_Flow_Statement])</span></span></span></span></span></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTX-With-VALUES.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/COUNTX-With-VALUES_thumb.jpg" alt="COUNTX With VALUES()" width="402" height="307" border="0" /></a></p>
<p>We have a result!  And our Working Capital section is behaving itself too!</p>
<h3>And now for the Subtotal Switch On / Off Measure</h3>
<p>Consider our two measures:</p>
<ol>
<li><strong>CF3_Total_Reqd</strong> this tells us when a total is required ie <strong>CF3_Total_Reqd &gt; 1</strong></li>
<li><strong>CF3_Total_Reqd</strong> also tells us where detailed elements exist, ie returns a value of 1, but this measure does the same for those associated subtotals.  <strong>CF4_Headings_No</strong>, at the same time, helps us distinguish, generally and irrespective of context, between detail and subtotal levels on our report ie <strong>CF3_Total_Reqd = 1 AND CF4_Headings_No = 1</strong></li>
</ol>
<p>If we combine these elements, we get a measure that we’ll call <strong>Cash_Flow_Heading_Tidy</strong></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">Cash_Flow_Heading_Tidy</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">=IF(</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">[CF3_Total_Reqd]&gt;1||</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">([CF3_Total_Reqd]=1&amp;&amp;[CF4_Headings_No]=1),</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">[Cash_Flow_Statement],</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">BLANK()</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">)</span></span></span></span></span></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-Major-Subtotals.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-Major-Subtotals_thumb.jpg" alt="Cash Flow Statement Major Subtotals" width="642" height="458" border="0" /></a></p>
<p>That gives us what we want, right?  Well not quite.  The <strong>Cash Flow From Operations</strong> section is now right.  However, the other sections in my <strong>CF2_Name</strong> column have reached the criteria for their totals to be eliminated.  If I don’t want this effect (and I don’t because this is a major total), I have to specify for my <strong>Cash_Flow_Heading_Tidy</strong> to directly include those totals.</p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">Cash_Flow_Heading_Tidy</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">=IF([CF3_Total_Reqd]&gt;1||</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">([CF3_Total_Reqd]=1&amp;&amp;[CF4_Headings_No]=1)||</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small"><strong>COUNTROWS(VALUES(CF3[CF3_Name]))&gt;1</strong>,</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">[Cash_Flow_Statement],</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">BLANK()</span></span></span></span></span></p>
<p style="line-height: normal;margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small"><span style="font-size: small">)</span></span></span></span></span></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-Complete.jpg"><img style="margin: 0px 5px;padding-left: 0px;padding-right: 0px;padding-top: 0px;border-width: 0px" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/Cash-Flow-Statement-Complete_thumb.jpg" alt="Cash Flow Statement Complete" width="642" height="501" border="0" /></a></p>
<p>There you have it.  All subtotals behaving properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2012/01/switching-subtotals-on-off-dynamically-using-dax-in-powerpivot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cash Flow Statement in PowerPivot</title>
		<link>http://www.powerpivotpro.com/2011/12/cash-flow-statement-in-powerpivot/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cash-flow-statement-in-powerpivot</link>
		<comments>http://www.powerpivotpro.com/2011/12/cash-flow-statement-in-powerpivot/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 05:01:00 +0000</pubDate>
		<dc:creator>David Churchward</dc:creator>
				<category><![CDATA[Accounting/Financial Techniques]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Accounting and Finance Techniques]]></category>
		<category><![CDATA[BI]]></category>
		<category><![CDATA[Cash Flow Statement]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[PowerPivot]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/?p=3343</guid>
		<description><![CDATA[&#160; Guest Post by David Churchward There’s few, if any, reports that I consider to be more important than the Cash Flow Statement.&#160; Every business needs one, probably above any other report.&#160; There’s numerous different versions of Cash Flow reports and, in reality, it can become a very personal thing to a company so I’m [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><em>Guest Post by </em><strong><a href="http://linkd.in/pNwvk4" target="_blank">David Churchward</a></strong></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image34.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cash Flow Statement" border="0" alt="Cash Flow Statement" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb33.png" width="642" height="373"></a></p>
<p>There’s few, if any, reports that I consider to be more important than the Cash Flow Statement.&nbsp; Every business needs one, probably above any other report.&nbsp; There’s numerous different versions of Cash Flow reports and, in reality, it can become a very personal thing to a company so I’m <strong>not</strong> going to propose to provide a <strong>one size fits all</strong> report.&nbsp; In addition, I’m not going to proclaim to provide an IAS7 – Cash Flow Statement (that’s International Accounting Standards) textbook report because this isn’t designed as an accountancy lesson (but, if you’re interested, the method I’ll show here relates to the Indirect Method in IAS7).</p>
<p>With that said, if you consider this post alongside Kasper’s excellent post <a href="http://www.powerpivotpro.com/2010/06/building-a-cash-flow-statement-in-powerpivot-using-dynamic-measures-in-dax/" target="_blank"><strong>Building a cash flow statement in PowerPivot using Dynamic Measures in DAX</strong></a>, you should have all the tools you need to produce any Cash Flow Statement that you require.</p>
<h3>The Accountancy Bit (very quickly!)</h3>
<p>Just before we start, a quick accountancy point to consider.&nbsp; Kasper’s approach considers cash payment and receipt transactions.&nbsp; My model uses all transactions in the general ledger with the exception of Bank transactions.&nbsp; On the basis that double entry exists (ie every transaction has an equal and opposite effect), all transactions that <strong>aren’t</strong> the bank transactions must equate to the same value.&nbsp; The reason we use the “other” side of the account is because this side of the transaction tells us what the cash transaction was for.&nbsp; As a result, we should simply be able to aggregate transactions into Cash Flow categories.</p>
<p>This seems quite straight forward.&nbsp; Unfortunately, there are a few exceptions that need to be handled.&nbsp; I’m only going to explain one which should give you the means to adjust for others.</p>
<p><strong>Depreciation</strong> is purely an accounting adjustment.&nbsp; This has the effect of crediting the balance sheet and debiting the P&amp;L.&nbsp; The effect of crediting the balance sheet has the effect of reducing the value that will be shown as Fixed Asset additions.&nbsp; We therefore net off the depreciation transaction as if it never happened and I’ll show this later in this post.</p>
<h3>The Dataset</h3>
<p>My dataset (FACT table) contains 3 columns:</p>
<ol>
<li><strong>GL_Account</strong>– this is my general ledger code.&nbsp; Every transaction that forms the trial balance will carry a general ledger code and this tells us what the transaction was for.
<li><strong>Month_End_Date</strong> – this date tells us the financial period to which the transaction relates.&nbsp; I would advise using the month end date of the financial period in which the transaction will be reported as I’m doing in this example. (or a period number as in Rob’s <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/" target="_blank">Greatest Formula In The World</a>&nbsp;</strong>posts).&nbsp; It should be noted that a transaction date may not be in the same calendar period as the reporting date so care should be taken.
<li><strong>Amount</strong>– this is the transaction value.&nbsp; Using normal accounting signage, this will be a positive value for debits and a negative value for credits. </li>
</ol>
<p>My dataset contains all transactions processed on the system – this is PowerPivot, it can handle it – and this essentially forms the basis of the trial balance.&nbsp; If you have a lot of old data and don’t want to include it all, you could substitute historic data with <strong>opening balance values </strong>for each general ledger code.&nbsp; This simply aggregates a lot of old transactions into one balance (per general ledger code) for an opening balance date, whilst maintaining the overall integrity of a balanced trial balance and the associated values.</p>
<p>You may have a dataset that holds monthly values for each general ledger code as opposed to each individual transaction.&nbsp; This will work equally well although you won’t have the means to dissect the Cash Flow Statement by subset records such as customer or project.</p>
<p>If your data is held as monthly columns, it’s worth running an <a href="http://www.powerpivotpro.com/2011/11/sql-unpivot-makes-my-data-skinny/" target="_blank"><strong>UNPIVOT</strong></a>.&nbsp; Whilst we could condition PowerPivot to work with individual values for each period, it’s more efficient to work with one value column with associated period dates held in another column.</p>
<h4>Related Tables</h4>
<p>I link my my FACT table to a GL_ACCOUNTS table on the GL_Account code.&nbsp; The GL_Accounts table provides details relating to the GL_Code such as account name and&nbsp; report heading codes.&nbsp; These heading codes, in turn, link through to a further GL_Headings table which holds cash flow report heading codes.&nbsp; This, in turn, links through to cash flow heading tables.&nbsp; It’s these headings that we will use on our Cash Flow Statement report.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image32.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="Cash Flow Statement Dataset Schema" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb31.png" width="642" height="322"></a></p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image22.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb21.png" width="433" height="286"></a></p>
<p>You’ll notice that CF1 doesn’t link to any other tables.&nbsp; I’ll come onto that shortly.</p>
<h3></h3>
<h3>General Ledger Account Mappings</h3>
<p>The GL_Headings mapping is the critical element to this dataset.&nbsp; This provides all of the key relationships between a general ledger code and the Cash Flow Statement report heading that you want the account to be represented under.</p>
<h4>GL_Headings Table</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image23.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb22.png" width="621" height="430"></a></p>
<p>My GL_Accounts map through to my Heading_Code on this GL_Headings table.&nbsp; This table holds all of my key report headings and provides a useful grouping of accounts.&nbsp; For instance, all general ledger codes that relate to Sales will carry a Heading_Code of 1010.</p>
<p>These definitions are important.&nbsp; This is a one-off setup and you’ve probably done this indirectly in some way or another to drive any reports or Excel analysis that you’re currently doing (probably with VLOOKUP).&nbsp; This process simply affirms that mapping.&nbsp; Ideally, you would code these heading codes into your General Ledger account code setup and formulate the code allocation as part of the process to set up new general ledger accounts.</p>
<p>You’ll recall that I mentioned <strong>Depreciation</strong> earlier in this post.&nbsp; Whilst this is a P&amp;L account (heading code 1045 in this example), I’m coding this to exactly the same place as Fixed Assets on the Balance Sheet (heading code 2010).&nbsp; This effectively eliminates the deprecation transactions.&nbsp; An alternative would be to filter out the accounts in question.&nbsp; You can do this, but be careful to ensure that those accounts net to zero.</p>
<p>Each of these codes map through to Cash Flow Statement heading tables.&nbsp; These heading tables can be whatever you need them to be, with headings and ordering assigned however you want your final report to be represented.&nbsp; The one’s I’m using are shown below.</p>
<h4>CF2 – Cash Flow Statement Heading 2</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image24.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb23.png" width="323" height="100"></a></p>
<p>This is my first grouping of headings.&nbsp; These align with the IAS7 headings for CF2 codes 1, 2 and 3 and basically split my Cash Flow Statement between Operations Activities, Investing Activities and Financing Activities.</p>
<p>There’s a fourth section called Bank.&nbsp; The Bank general ledger codes map through to this code and we eliminate them for the Cash Flow element of this report.&nbsp; However, we bring them back into action when we display the Bank Balances at the end of the report.</p>
<h4>CF3 – Cash Flow Statement Heading 3</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image25.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb24.png" width="509" height="251"></a></p>
<p>This is the next level of granularity on my report.&nbsp; The Bank general ledger codes <strong>don’t</strong> have any CF3 mapping and yet I’m carrying Opening and Closing Bank Balance codes on this heading set.&nbsp; I’ll come onto why that is a bit later.&nbsp; You’ll also notice that I’ve coded these headings with an Open_Bank&nbsp; and Close_Bank flag.&nbsp; We’ll use dynamic DAX measures later on to utilise these.</p>
<p><strong>Note – there should NOT be any mapping of accounts to the CF3 codes 10 and 11 in this table (ie Open and Close Bank Balance).&nbsp; We’ll use these simply to drive a DAX measure later.</strong></p>
<h4>CF4 – Cash Flow Statement Heading 4</h4>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image26.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb25.png" width="295" height="113"></a></p>
<p>One element of my Cash Flow Statement will carry a further breakdown – Working Capital (although you can have more if you want).&nbsp; I’ve done this simply to provide an extra level of granularity, but you could decide to replace the Working Capital heading in CF3 with these headings and map accordingly.</p>
<p>I’ve got a few reasons for doing this:</p>
<ol>
<li>I like to show my Working Capital elements specifically – this targets the key operational balance sheet items that generally need to be tracked
<li>This helps to line up a future post! </li>
</ol>
<h4>CF1 – Cash Flow Statement Heading 1</h4>
<p>You might, quite rightly, question why my ordering has gone to pot and I’m explaining CF1 last!&nbsp; Quite simply, this table sits out on it’s own because it simply drives report sections as opposed to being a mapped heading code.&nbsp; I’m going to show a Cash Flow section and then, below that, I’m going to show the effect on the bank balance.&nbsp; No relationships required.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image27.png"><img style="border-right-width: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb26.png" width="230" height="66"></a></p>
<h4></h4>
<h4></h4>
<h3>And Now for the DAX – Cash Flow</h3>
<p>I’ve got to be honest, this measure isn’t going to set the world alight.&nbsp; However, this goes to show how easy PowerPivot can be, especially if you condition your data properly.&nbsp; I’m creating a measure aptly called Cash_Flow</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">Cash_Flow</span></span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">=CALCULATE(</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">SUM(FACT[Amount]),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">CF2[CF2_Name]&lt;&gt;&#8221;BANK&#8221;</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )*-1</span></span></span></span></p>
<p>This is a simple CALCULATE function which sums the [Amount] field on the FACT table with a simple filter set to ignore any GL_Accounts that have a CF2 category mapping of “<strong>BANK</strong>”.</p>
<p>You’ll notice that I multiply this by –1 to reverse the signage.&nbsp; In simple terms this is because of the double entry effect.&nbsp; We’re using the “<strong>other</strong>” side of the transaction which means that the sign convention is going to be back to front.&nbsp; This simply reverses that effect.</p>
<p>When I pull this measure onto my report together with the CF1,2,3,4 heading names, I get the following.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image35.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cash Flow in Excel - PowerPivot Turns Complex into Simple" border="0" alt="Cash Flow in Excel - PowerPivot Turns Complex into Simple" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb34.png" width="642" height="383"></a></p>
<p>You might say that this is job done (especially if you remove CF1 heading from the report). This does give us a Cash Flow Statement. However, this doesn’t give my bank balances and, if I include my CF1 heading, my report is repeating the same data for both of the CF1_Name headings. This is understandable as CF1 is <strong>not</strong> linked to my FACT table in anyway.&nbsp; This is intentional (believe it or not!).</p>
<h4></h4>
<h4>Bank Balances</h4>
<p>I want to show opening and closing bank balances for the Bank section of my report and this is where it gets a bit more interesting.&nbsp; Let’s create a measure that calculates these balances and let’s call this measure Bank…</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">Bank</span></span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">=IF(COUNTROWS(VALUES(CF3[CF3]))=1,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">IF(VALUES(CF3[Close_Bank])=1,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">CALCULATE(</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">SUM(FACT[Amount]),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">ALL(CF3),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">CF2[CF2_Name]=&#8221;BANK&#8221;,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">FILTER(</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">ALL(Month_End_Dates[MonthEndDate]),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">Month_End_Dates[MonthEndDate]&lt;=</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">MAX(Month_End_Dates[MonthEndDate])</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">IF(VALUES(CF3[Open_Bank])=1,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">CALCULATE(</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">SUM(FACT[Amount]),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">ALL(CF3),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">CF2[CF2_Name]=&#8221;BANK&#8221;,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.125in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">FILTER(</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">ALL(Month_End_Dates[MonthEndDate]),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">Month_End_Dates[MonthEndDate]&lt;=</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.875in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">EOMONTH(MAX(Month_End_Dates[MonthEndDate]),-1)</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp; )</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 1.5in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">),</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">BLANK()</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.75in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp; )</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp;&nbsp; )</span></span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )</span></span></span></span></p>
<p>We should be offering prizes for those of you would can instantly spot the <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/" target="_blank">GFITW</a> </strong>elements!!&nbsp; Anyone would think that this had somehow been contrived!&nbsp; Believe me – it hasn’t.&nbsp; This is a concept that I use regularly and it’s a joy to see Rob explain it so well so I don’t have to!</p>
<p>So what is this doing?&nbsp; I’ll explain as clearly as I can, but it’s worth paying very close attention to Rob’s <a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/" target="_blank"><strong>Greatest Formula In The World</strong></a> posts.&nbsp; I won’t re-iterate too much here.</p>
<ol>
<li>The first IF statement simply serves to provide an answer as to where I want the measure to be evaluated.&nbsp; I want an answer when my CF3_Heading is flagged as Open_Bank or Close_Bank.
<li>The second IF statement creates a value when my CF3_Heading [Close_Bank] is flagged.&nbsp; Where this is the case, the following happens:
<ol>
<li>Sum the [Amount] Field
<li>Expand my dataset to all CF3 headings in order to release the dependency on the current CF3 heading being evaluated – <strong>ALL(CF3)</strong>
<li>Apply a filter to include all of my Bank general ledger codes – <strong>CF2[CF3_Name]=”BANK”</strong>
<li>Apply a further filter (FILTER) that:
<ol>
<li>Removes the dependency on the MonthEndDate – <strong>ALL(Month_End_Dates[MonthEndDate])</strong>
<li>Apply a filter that includes all months that pre-date and include the reporting month – <strong>Month_End_Dates[MonthEndDate]&lt;=MAX(Month_End_Dates[MonthEndDate])</strong> – this is important because the transaction base for the month won’t give us the balance.&nbsp; We need to include ALL transactions that pre-date and include the reporting date. </li>
</ol>
</li>
</ol>
<li>The third IF statement has a similar effect to the second IF statement, but it produces an opening balance and therefore the current reporting month has to be ignored.&nbsp; As a result, I want to sum all transactions where the date is less than or equal to my prior month date &#8211; <strong>Month_End_Dates[MonthEndDate]&lt;=EOMONTH(<strong>MAX(Month_End_Dates[MonthEndDate])</strong> ,-1)</strong> </li>
</ol>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image36.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cash Flow in Excel with Bank Balances Thanks to PowerPivot" border="0" alt="Cash Flow in Excel with Bank Balances Thanks to PowerPivot" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb35.png" width="642" height="290"></a></p>
<p>Once again, we have the correct results but we’re getting values repeated for both CF1 headings.</p>
<h4>Sorting Those CF1 Headings</h4>
<p>We now have our two base measures.&nbsp; All we now need to do is evaluate when to use each one.&nbsp; Let’s create another measure called Cash_Flow_Statement.</p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">Cash_Flow_Statement</span></span></span></span></p>
<p style="line-height: normal; margin: 0in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">=IF(COUNTROWS(VALUES(CF1[CF1]))=1,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">IF(VALUES(CF1[CF1])=1,</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">[Cash_Flow],</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">[Bank]</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">&nbsp;&nbsp; )</span></span></span></span></p>
<p style="line-height: normal; margin: 0in 0in 0in 0.375in"><span style="font-family: courier new"><span style="color: #000000"><span style="font-size: small"><span style="font-size: small">)</span></span></span></span></p>
<p>This measure simply evaluates for CF1 headings and determines that if my CF1 Heading Code is 1 (ie Cash Flow) then use my [Cash_Flow] measure.&nbsp; Otherwise, use my [BANK] measure.</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image37.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cash Flow Finished" border="0" alt="Cash Flow Finished" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb36.png" width="642" height="386"></a></p>
<p>A bit of formatting and there you have it.&nbsp; You’re just about done.&nbsp; Or rather, you’re done if you think that’s enough.&nbsp; I, however, don’t like some of these totals and duplication of values in certain areas.&nbsp; <strong>There’s a way to deal with those totals but that’s a topic for a future post</strong>.</p>
<h3>So what else can we do with this?</h3>
<p>Just as a taster, here’s something that I like to call a Cash Flow Bridge.&nbsp; This could be a topic for a future post, but just to whet your appetite……</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image33.png"><img style="border-right-width: 0px; margin: 0px 5px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Cash Flow Statement Bridge" border="0" alt="Cash Flow Statement Bridge" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb32.png" width="642" height="351"></a></p>
<p>If there’s enough call for this, I’ll get this scheduled in for a future post.&nbsp; Neat eh!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2011/12/cash-flow-statement-in-powerpivot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Greatest Formula in the World, Part 3</title>
		<link>http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-greatest-formula-in-the-world-part-3</link>
		<comments>http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 16:11:02 +0000</pubDate>
		<dc:creator>powerpivotpro</dc:creator>
				<category><![CDATA[Custom Calendars]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Time Intelligence]]></category>
		<category><![CDATA[PowerPivot Power Pivot Microsoft SharePoint BI Excel Business Intelligence DAX]]></category>

		<guid isPermaLink="false">http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/</guid>
		<description><![CDATA[&#160;Our time machine that we developed in part one and part two still needs some explanation, so let’s dive in. First Things First:&#160; The MAXX Wasn’t Needed Looking back, I noticed that I was overcomplicating things needlessly.&#160; The final formula I had involved the following FILTER() term, in which I used a MAXX: FILTER(ALL(Periods), &#160;&#160;&#160;&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;<br />Our time machine that we developed in <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-one/">part one</a></strong> and <strong><a href="http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-two/">part two</a></strong> still needs some explanation, so let’s dive in.</p>
<h3>First Things First:&nbsp; The MAXX Wasn’t Needed</h3>
<p>Looking back, I noticed that I was overcomplicating things needlessly.&nbsp; The final formula I had involved the following FILTER() term, in which I used a MAXX:</p>
<p><font size="3" face="Courier New">FILTER(ALL(Periods), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Periods[NextYear Period]&lt;=<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em><strong>MAXX(VALUES(Sales[Period Num]), Sales[Period Num])</strong><br /></em>)<br /></font></p>
<p>Turns out that MAX() works just fine, so let’s replace that clause and simplify things a bit.&nbsp; Here&#8217;s the new formula:</p>
<p><font size="3" face="Courier New">CALCULATE([Total Sales], <br />&nbsp;&nbsp; ALL(Periods), <br />&nbsp;&nbsp; FILTER(ALL(Periods), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Periods[Year]=MAX(Periods[Year])-1<br />&nbsp;&nbsp; ), <br />&nbsp;&nbsp; FILTER(ALL(Periods), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Periods[NextYear Period]&lt;=<strong><em>MAX(Sales[Period Num])</em></strong><br />&nbsp;&nbsp; ),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; VALUES(Periods[MerchPeriod])<br />)</font></p>
<p>OK, with that, we can move on to explanation:&nbsp; How does this formula work??</p>
<h3>I used to call this technique “expand then filter”</h3>
<p>Well actually I still do, in my own head.&nbsp; It’s just that the GFITW is a catchier title.</p>
<p>OK, so the “expand” part is just that first ALL():</p>
<p><font size="3" face="Courier New">CALCULATE([Total Sales], <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><em>ALL(Periods),</em></strong> <br /></font>
<p>The first step in the formula, then, is basically just telling the calc engine to throw away all filters on the Periods table.&nbsp; In other words, “forget all concept of time, pretend the pivot is not filtered at all with respect to time.”</p>
<p>We do this so that we have a clean slate.&nbsp; Then, in the subsequent FILTER clauses, we build up a <strong>new</strong> filter context for time.</p>
<p>One more time for clarity:&nbsp; <strong>the way this formula works is to first throw out all time filters, and then in subsequent steps, we build up new filters to match the time period that we want</strong>, which in this case is last year.</p>
<p>Once you understand that, this overall formula starts to get pretty simple.&nbsp; Each piece of the formula is quite straightforward in its own right.&nbsp; ALL() is pretty straightforward for sure, and so are the subsequent FILTERS().</p>
<h3>OK, we’ve expanded.&nbsp; Now on to the filters!</h3>
<p>The first filter says, “hey, now that we’ve thrown out all time filters, let’s filter time back down to just be last year.”</p>
<p><font size="3" face="Courier New">FILTER(ALL(Periods), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Periods[Year]=MAX(Periods[Year])-1<br />)</font>
<p>Let’s talk about the FILTER() function itself for a moment.</p>
<h3>How does FILTER() Work?</h3>
<p>Honestly this function has deserved its own post for a long time.&nbsp; I’ll give a brief explanation here.</p>
<p>The syntax for the FILTER function is FILTER(<em>TableToFilter</em>, <em>FilterExpression</em>).&nbsp;&nbsp; Pretty simple.&nbsp; Here’s some more detail:</p>
<ol>
<li><strong>FILTER() takes a <em>TableToFilter </em>and a <em>FilterExpression</em>, and returns all rows from that <em>TableToFilter </em>that match the <em>FilterExpression</em>.</strong></li>
<ol>
<li>In the example above, <em>TableToFilter </em>is ALL(Periods)</li>
<li>and <em>FilterExpression</em> is Periods[Year]=MAX(Periods[Year])-1</li>
</ol>
<li><strong>FILTER() steps through the <em>TableToFilter </em>one row at a time.</strong>&nbsp; </li>
<ol>
<li>And for each row, it evaluates the <em>FilterExpression</em>.&nbsp; If the expression evaluates to true, the row is “kept.”&nbsp; If not, it is filtered out. </li>
<li>Because FILTER() goes one row at a time, it can be quite slow if you use it against a large table.&nbsp; When I say “large” that is of course subjective.&nbsp; A few thousand rows is fine in my experience.&nbsp; A million is not.&nbsp; Do not use FILTER() against your fact table.</li>
</ol>
<li><strong>The <em>FilterExpression </em>typically takes the form of Table[Column] = &lt;expression&gt;</strong></li>
<ol>
<li>The comparison operator doesn’t have to be “=”.&nbsp; It can also be &lt;, &gt;, &lt;=, &gt;=, &lt;&gt;</li>
<li>The expression on the right hand side of <em>FilterExpression </em>can be “rich.”&nbsp; This is VERY useful.&nbsp; In a simple CALCULATE, the right side of each filter expression has to be simple, like a literal number (9) or a string (“Standard”).&nbsp; The fact that FILTER() allows for rich expressions here is one of the most common reasons I use FILTER().</li>
<li>The Table[Column] in the filter expression is a column in the <em>TableToFilter</em>.&nbsp; If you are filtering the Periods table, it makes sense that you are testing some property of each row in Periods.&nbsp; I can’t think of a sensible reason to use a column here that is NOT from <em>TableToFilter.</em>&nbsp; (Insert “<a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image18.png">boot signal</a>” here, maybe the Italians can address this).</li>
</ol>
<li><strong>FILTER() ignores everything else going on in your formula and acts completely on its own.</strong></li>
<ol>
<li>For example, our overall formula sets ALL(Periods) as the first argument to CALCULATE.</li>
<li>The FILTER()’s that come after that do NOT pay any attention to other arguments however, including that ALL(Periods).</li>
<li>In other words, the FILTER() functions are still operating against the original filter context from the pivot!&nbsp; If the pivot is sliced to Year=2009, then the FILTER() function starts with the Periods table already pre-filtered to just 2009.</li>
<li>This is why each of my FILTER()’s uses ALL(Periods) for <em>TableToFilter.</em>&nbsp; I have to repeat the “expand” step so that my FILTER() is also working from a clean slate.</li>
</ol>
<li><strong>Even though each FILTER() operates on its own, their results then “stack up” in the overall formula.</strong></li>
<ol>
<li>Even though FILTER() RETURNS a set of rows that matched the <em>FilterExpression, </em>it actually REMOVES rows from the overall filter context.</li>
<li>This sounds tricky but really it isn’t.</li>
<li>Let’s say our <em>TableToFilter </em>contains 6 rows:&nbsp; A, B, C, D, E, and F.</li>
<li>And our overall formula contains two FILTER() clauses that both operate on the same <em>TableToFilter</em>, just like our overall formula near the beginning of this post.</li>
<li>Let’s also say that the first FILTER() returns rows A, B, C, and D.</li>
<li>And the second FILTER() returns rows C, D, E, and F.</li>
<li>The net result is that only rows C and D are left “alive” in the overall filter context of the formula.</li>
<li>So one way to think of this is that FILTER()s “stack up” on top of each other.</li>
<li>Another way to think of it is that even though the first filter RETURNED rows A, B, C, and D, its real effect was to <em>REMOVE all other rows</em> (E and F) from consideration.</li>
</ol>
</ol>
<h3>OK, back to that first filter!</h3>
<p>Here it is again:</p>
<p><font size="3" face="Courier New">FILTER(ALL(Periods), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Periods[Year]=MAX(Periods[Year])-1<br />)</font>
<p>Let’s revisit points 1-5 above for this FILTER expression to see how it all works.&nbsp; And let’s examine just a single cell of the pivot to see how this FILTER operates for that one cell:</p>
<p><a href="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image19.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px auto; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.powerpivotpro.com/wp-content/uploads/2011/12/image_thumb18.png" width="244" height="421"></a></p>
<p align="center"><strong>Focusing on The Orange-Circled LASTYRSALES Cell As An Example <br />With Its Period Filter Context Highlighted in Green</strong></p>
<p>In that picture above, the orange cell we are looking at has a filter context “coming in” from the pivot.&nbsp; It has Period[Year] set to 2011 and Period[MerchPeriod] set to 1, as highlighted in green.</p>
<p>Given the detailed description of FILTER() from points 1-5 above, we can see that:</p>
<ol>
<li><strong>We set ALL(Periods) as our </strong><em><strong>TableToFilter</strong> </em>so that we are starting from a clean slate with respect to time.&nbsp; So our Periods table now has “all rows alive.”</li>
<li><strong>Then our <em>FilterExpression </em>tests against the Periods[Year] column.</strong></li>
<li><strong>MAX(Periods[Year]) &#8211; 1 still operates independently!</strong>, so it still picks up Periods[Year]=2011 from the pivot.&nbsp; Therefore it returns 2011 – 1 = 2010!</li>
<li><strong>Since we started with ALL(Periods) as the <em>TableToFilter</em>,</strong> and the <em>FilterExpression </em>only “keeps” rows where Year=2010, we are left with all 2010 rows “alive” after evaluating this FILTER().</li>
<li><strong>If we didn’t do ALL(Periods) for <em>TableToFilter</em>, and instead just used Periods</strong> without the ALL(), our FILTER would start out with only rows from 2011 (since that is what the pivot is telling us).</li>
<ol>
<li>And then in the next step when we go back a year to 2010, FILTER() would find no rows.&nbsp; There are no rows that match Periods[Year] = 2010 and Periods[Year]=2011.&nbsp; </li>
<li>So our FILTER would return no rows, which means it would have the effect of REMOVING all rows from Periods in the overall formula, and our measure would return blank for all cells in the pivot.</li>
</ol>
</ol>
<p>That’s a lot of explanation, I know.&nbsp; Walk through it a few times.&nbsp; It’s actually pretty intuitive once you’ve done it a few times.&nbsp; The tricky part, for me, was discovering all of these details for myself.&nbsp; And since I’ve done all of that, you don’t have to.</p>
<p>That’s enough for this time.&nbsp; I think you can probably figure out how the second FILTER() evaluates based on the above, but I will step through it next time.&nbsp; </p>
<p>I will also explain why we use that last VALUES() in the formula, and probably also share some of the answers I got from the Italians, and from David Churchward, in response to my question “did I need to add that calc column in the Periods table?”</p>
]]></content:encoded>
			<wfw:commentRss>http://www.powerpivotpro.com/2011/12/the-greatest-formula-in-the-world-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

