<?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>nested calculation Archives - KDD Analytics</title>
	<atom:link href="https://www.kddanalytics.com/tag/nested-calculation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kddanalytics.com/tag/nested-calculation/</link>
	<description>Data to Decisions</description>
	<lastBuildDate>Sun, 16 Jul 2017 17:59:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2016/08/cropped-imageedit_1_7939659602.png?fit=32%2C32&#038;ssl=1</url>
	<title>nested calculation Archives - KDD Analytics</title>
	<link>https://www.kddanalytics.com/tag/nested-calculation/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">114932494</site>	<item>
		<title>Nested Calculation – A Tableau Puzzler</title>
		<link>https://www.kddanalytics.com/nested-calculation-tableau-puzzler/</link>
		
		<dc:creator><![CDATA[KDD]]></dc:creator>
		<pubDate>Thu, 20 Jul 2017 01:48:32 +0000</pubDate>
				<category><![CDATA[Tableau]]></category>
		<category><![CDATA[nested calculation]]></category>
		<guid isPermaLink="false">http://www.kddanalytics.com/?p=964</guid>

					<description><![CDATA[<p>Tableau is a powerful tool for visualizing data.  It is easy to throw data into, to start exploring data and to begin creating charts.  But there is a lot going on “under the hood” and more advanced analytics requires a bit of a learning curve to get Tableau to do what you want it to&#8230;</p>
<p>The post <a href="https://www.kddanalytics.com/nested-calculation-tableau-puzzler/">Nested Calculation – A Tableau Puzzler</a> appeared first on <a href="https://www.kddanalytics.com">KDD Analytics</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="color: #60786b;"><em>Tableau is a powerful tool for visualizing data.  It is easy to throw data into, to start exploring data and to begin creating charts.  But there is a lot going on “under the hood” and more advanced analytics requires a bit of a learning curve to get Tableau to do what you want it to do.</em></span></p>
<p><span style="color: #60786b;"><em>Anyone who has worked with Tableau for any length of time will run into “puzzlers”.  Something that, on the face of it, logically should work.  But it just doesn’t!  This can lead one down a &#8220;rabbit hole&#8221; in search of an answer from colleagues, Tableau’s community forum, Tableau blogger sites, Tableau’s online manual and, finally, Tableau’s (most excellent!) support.  Hours can be spent on what, again, on the face of it, should be a simple calculation.</em></span></p>
<p><span style="color: #60786b;"><em>But once learned, never forgotten, right?</em></span></p>
<p><span style="color: #60786b;"><em>Here is one we ran into recently, the answer to which hopefully saves other Tableau users from such a &#8220;rabbit hole&#8221; adventure.</em></span></p>
<h3>The setup</h3>
<p>Envision an Excel table which shows data for two variables (X and Y) from two machines (A and B) over time (in 1/2-hour increments).  Something like this, a “short and wide” table:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-large wp-image-970" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-6d.png?resize=1024%2C177&#038;ssl=1" alt="" width="1024" height="177" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-6d.png?resize=1024%2C177&amp;ssl=1 1024w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-6d.png?resize=300%2C52&amp;ssl=1 300w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-6d.png?resize=768%2C133&amp;ssl=1 768w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-6d.png?w=1794&amp;ssl=1 1794w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></p>
<p>Now suppose we want to sum variable X (Y) over time for each machine, express these sums as a ratio for each machine and then calculate the average ratio across both machines.  We can easily do this in Excel to yield:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone wp-image-972 size-large" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-7d.png?resize=1024%2C189&#038;ssl=1" alt="" width="1024" height="189" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-7d.png?resize=1024%2C189&amp;ssl=1 1024w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-7d.png?resize=300%2C55&amp;ssl=1 300w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-7d.png?resize=768%2C142&amp;ssl=1 768w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-7d.png?w=1383&amp;ssl=1 1383w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></p>
<h3>Now what about Tableau?</h3>
<p>Following how this is done in Excel, in Tableau, we would:</p>
<ol>
<li>Put time on the columns shelf and the “dimension” machines on the row shelf;</li>
<li>Create a calculated field for the sum of Var X as window_sum([Var X]) and do the same for the sum of Var Y (window_sum([Var Y]);</li>
<li>Place Sum Var X and Sum Var Y on the columns shelf, right click on the “Δ” in the measure value pill and set each to “Compute Using” Table (across) since we have time going from left to right;</li>
<li>Filter to show only the last time increment using last()==0 set equal to “true”.</li>
</ol>
<p>This yields the following view:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-974" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-1.gif?resize=829%2C573&#038;ssl=1" alt="" width="829" height="573" /></p>
<p>So far, so good.  Now we can add the ratio of Sum Var X to Sum Var Y by creating another calculated field [Sum Var X]/[Sum Var Y], adding it as the 3<sup>rd</sup> measure value and set “Compute Using” to Table (across):</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-975" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-2.png?resize=832%2C591&#038;ssl=1" alt="" width="832" height="591" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-2.png?w=832&amp;ssl=1 832w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-2.png?resize=300%2C213&amp;ssl=1 300w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-2.png?resize=768%2C546&amp;ssl=1 768w" sizes="auto, (max-width: 832px) 100vw, 832px" /></p>
<p>Good.  Now the last step is to find the average (Sum Var X / Sum Var Y) <strong>across the two machines</strong>.  Which from Excel, we know is 12.18%.  So, let’s create another calculated field as window_avg([Sum Var X / Sum Var Y]), place it as our 4<sup>th</sup> measure value and set “Compute Using” as <strong>Table (down)</strong> since now we want the average across machines:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-976" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-3.png?resize=832%2C624&#038;ssl=1" alt="" width="832" height="624" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-3.png?w=832&amp;ssl=1 832w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-3.png?resize=300%2C225&amp;ssl=1 300w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-3.png?resize=768%2C576&amp;ssl=1 768w" sizes="auto, (max-width: 832px) 100vw, 832px" /></p>
<p>Uh oh.  What happened?  We are not getting 12.18%.  Logically it should work…compute using Table (down), right?</p>
<h3>Nested calculation</h3>
<p>The average of (Sum Var X / Sum Var Y) is a “nested table calculation”.  If you right click on the “Δ” in the measure value pill for Avg (Sum Var X / Sum Var Y) and then click on “Edit Table Calculation” you will see the following:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-977" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-4.png?resize=836%2C873&#038;ssl=1" alt="" width="836" height="873" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-4.png?w=836&amp;ssl=1 836w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-4.png?resize=287%2C300&amp;ssl=1 287w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-4.png?resize=768%2C802&amp;ssl=1 768w" sizes="auto, (max-width: 836px) 100vw, 836px" /></p>
<p>&nbsp;</p>
<p>Avg (Sum Var X / Sum Var Y) is a nested calculation because Sum Var X and Sum Var Y are themselves calculated values (window sums of var X (Y)).  Okay, so what?</p>
<p>Well, to get &#8220;Compute Using&#8221; Table (down) to work, you need to tell Tableau…and<strong> here is the trick</strong>…how Sum Var X and Sum Var Y are to be calculated <strong>inside the nested calculation</strong>.  This <strong>is true <em>even though you have alread</em>y told Tableau how to compute</strong> Sum Var X and Sum Var Y … we did this above … Table (across).  <strong>You need to do it again inside this Table Calculation dialog box</strong>.</p>
<p>In the Table Calculation dialog box, under “Nested Calculations”, click the upside-down triangle next to each of the components of the nested calculation (Sum Var X and Sum Var Y).  Then, for each one, select the correct “Compute Using”, which we know is <strong>Table (across</strong>).  Then, for avg(Sum Var X / Sum Var Y) choose <strong>Table (down)</strong>.  Close this dialog box and you will then show the correct calculation:</p>
<p><img data-recalc-dims="1" decoding="async" loading="lazy" class="alignnone size-full wp-image-978" src="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-5.png?resize=838%2C624&#038;ssl=1" alt="" width="838" height="624" srcset="https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-5.png?w=838&amp;ssl=1 838w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-5.png?resize=300%2C223&amp;ssl=1 300w, https://i0.wp.com/www.kddanalytics.com/wp-content/uploads/2017/07/TC-Example-5.png?resize=768%2C572&amp;ssl=1 768w" sizes="auto, (max-width: 838px) 100vw, 838px" /></p>
<h3>Other tips</h3>
<p>Note that if Sum Var X and Sum Var Y were not calculated values but rather “raw” values, then avg (Sum Var X / Sum Var Y) would not be a nested calculation.  Setting &#8220;Compute Using&#8221; to Table (down) without going into the Table Calculations dialog box would have worked in this case.</p>
<p><strong><u>Another tip (from Tableau support)</u></strong>: if you right click on the “Δ” in your measure value pill, select “Compute Using” and do <strong>NOT</strong> see any of the options already selected, then you know you have nested calculation.</p>
<p>So, if a calculated value is based on other calculated values, then you are “nested” and you need to pay special attention to how they are used in Table Calculations.</p>
<p>Hope this helps!</p>
<a class="dpsp-click-to-tweet dpsp-style-1" href="https://twitter.com/intent/tweet?text=If+a+calculated+value+is+based+on+other+calculated+values%2C+then+you+are+%E2%80%9Cnested%E2%80%9D+and+you+need+to+pay+special+attention+to+how+...+&url=https%3A%2F%2Fwww.kddanalytics.com%2Fnested-calculation-tableau-puzzler%2F"><div class="dpsp-click-to-tweet-content">If a calculated value is based on other calculated values, then you are “nested” and you need to pay special attention to how ... </div><div class="dpsp-click-to-tweet-footer"><span class="dpsp-click-to-tweet-cta"><span>Click to Tweet</span><i class="dpsp-network-btn dpsp-twitter"><span class="dpsp-network-icon"></span></i></span></div></a>
<p>The post <a href="https://www.kddanalytics.com/nested-calculation-tableau-puzzler/">Nested Calculation – A Tableau Puzzler</a> appeared first on <a href="https://www.kddanalytics.com">KDD Analytics</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">964</post-id>	</item>
	</channel>
</rss>
