<?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>Data Storytelling | Capstone Analytics</title>
	<atom:link href="https://capstoneanalytics.com.au/tag/data-storytelling/feed/" rel="self" type="application/rss+xml" />
	<link>https://capstoneanalytics.com.au</link>
	<description>Analytics Simplified</description>
	<lastBuildDate>Fri, 21 Feb 2025 00:17:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>How to solve business problems using DAX &#8211; Part 5: What is Australia&#8217;s share of global export coal revenue ?</title>
		<link>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-5-what-is-australias-share-of-global-export-coal-revenue/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-solve-business-problems-using-dax-part-5-what-is-australias-share-of-global-export-coal-revenue</link>
					<comments>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-5-what-is-australias-share-of-global-export-coal-revenue/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Fri, 01 Jul 2022 03:33:46 +0000</pubDate>
				<category><![CDATA[Mining Intelligence]]></category>
		<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Solve Business Problems]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2807</guid>

					<description><![CDATA[0In Part 4 of the series, we talked about how to solve business problems when you want to filter a measure using numeric and date expressions. In this series, we go to the next level of business problems where we discuss problems involving % of the total. These kind of problems are solved easily in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>0In <a href="https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-4-how-many-sales-orders-are-greater-than-3000/">Part 4</a> of the series, we talked about how to solve business problems when you want to filter a measure using numeric and date expressions. In this series, we go to the next level of business problems where we discuss problems involving % of the total. These kind of problems are solved easily in Excel but it requires advanced DAX knowledge to solve it in Power BI. We will be using the ALL family of functions to solve this problem.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; What is Australia&#8217;s share of global export coal revenue </strong></h3>
<p>&nbsp;</p>
<p>This problem involves calculating % of the total and is a common problem which needs to be solved in a business. Some other problems along the same lines:</p>
<ul>
<li>What is the % profit for each store last financial year</li>
<li>How much rainfall in % did Brisbane get this year among the top 5 Australian cities</li>
<li>What is the % of electric vehicles among all cars sold in Australia in 2021</li>
</ul>
<p>&nbsp;</p>
<p>For this problem we will be using data from this <a href="https://www.worldstopexports.com/coal-exports-country/">website</a> which gives the top 15 coal exporting countries by revenue which account for  98.6% of global coal exports in 2021. The data model is shown below</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2813" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.1.png" alt="" width="802" height="532" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.1.png 802w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.1-480x318.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 802px, 100vw" /></p>
<p>&nbsp;</p>
<p>Before calculating the measure for the % of the total we need to calculate the total, in this case the total export revenue</p>
<p>Export Revenue ($) =<br />
<span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Export'[Export Revenue] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>For the first iteration of the % of total we calculate the measure as</p>
<p>Export Revenue % v1 =<br />
<span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span>[Export Revenue ($)],<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> Location <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>In the denominator we are using  <span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> Location <span class="Parenthesis" style="color: #808080;">)</span> to remove any filters coming from the Location table and by doing that we get the total export revenue in the denominator. So for each country the numerator is the export revenue of that country and the denominator is the total export revenue and the ratio gives the %.</p>
<p>We place this two measures in a table visual along with the column &#8216;Country&#8217; and we get</p>
<p><img decoding="async" class="alignnone size-full wp-image-2814" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.2.png" alt="" width="491" height="488" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.2.png 491w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.2-480x477.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 491px, 100vw" /></p>
<p>So, to answer the question, Australia&#8217;s share of the global coal revenue is 36.2% in 2021.</p>
<p>Let&#8217;s add some complexity and start asking more questions</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; What is the export coal revenue for Asian countries as a percentage of Asia&#8217;s revenue</strong></h3>
<p>&nbsp;</p>
<p>There are six countries in Asia in the model- Indonesia, Mongolia, Kazakhstan, Philippines, China, and Vietnam. The problem is to calculate the export coal revenue of each of those countries as a % of Asia&#8217;s revenue. We have the column &#8216;Continent&#8217; available to us in the model, so we drag it into a slicer and select Asia and this happens</p>
<p>&nbsp;</p>
<p><img decoding="async" class="alignnone size-full wp-image-2816" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.3.png" alt="" width="626" height="222" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.3.png 626w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.3-480x170.png 480w" sizes="(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 626px, 100vw" /></p>
<p>Not quite the result we expected for the Export Revenue % v1 measure. Why is that ? Recall that the denominator of the <span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> </span>function in the measure uses  <span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> Location <span class="Parenthesis" style="color: #808080;">)</span>which removes filters from the Location table. Hence, even though we select Asia from the Continent column which is in the Location table, the filter from that column is removed giving all the rows of that table. Hence we get the % of the global export coal revenue and not Asia&#8217;s. We need to define another measure which retains the filters coming from the Continent column. We define it as below</p>
<p>&nbsp;</p>
<p>Export Revenue % v2 =<br />
<span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span>[Export Revenue ($)],<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>We have replaced  <span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> Location <span class="Parenthesis" style="color: #808080;">) with  <span class="Keyword" style="color: #035aca;">ALLSELECTED</span> ( Location[Country] ). What this does is gives all the rows from the selection, in this case we have selected &#8216;Asia&#8217; from the &#8216;Continent&#8217; column and this filter is applied on the measure and we get all the countries under &#8216;Asia&#8217;. Thus the denominator is the sum of the export revenue for Asia which is $30.66 bn.</span></p>
<p>We place this measure in the same visual as above and get the below</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2817" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.4.png" alt="" width="842" height="239" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.4.png 842w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.4-480x136.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 842px, 100vw" /></p>
<p>This is exactly the result we wanted. Indonesia has the biggest % share for all Asian countries at 86.4% followed by Mongolia at 6.2%. You can select any Continent in the slicer and the Export Revenue % v2 measure gives the % for the countries in that continent.</p>
<p>Let&#8217;s add a twist to the problem. What if we place Continent into the visual above and convert it into a matrix visual and expand to the lowest level (Country). From here on we would only be focusing on the v2 measure. The visual would look like this:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2819" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.5.png" alt="" width="546" height="530" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.5.png 546w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.5-480x466.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 546px, 100vw" /></p>
<p>&nbsp;</p>
<p>What we now have is that the % for the countries are correct but the % for the continents are wrong. Why is that ? Because in the denominator of the <span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> function the filter for continent is still present. Hence the numerator and denominator are one and the same and the ratio is 1.</span>  We need another set of measures which gives the correct % for the countries as well as the continents. WE define another measure which we wont be using in the visual but will be used in the subsequent v4 measure.</p>
<p>Export Revenue % v3 =<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Export'[Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>The above measure is used in the v4 measure which is defined as follows</p>
<p>Export Revenue % v4 =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISINSCOPE</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], [Export Revenue % v3] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span>[Export Revenue % v2]<br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>This measure has two parts. The first part applies to the rows in the visual with continents filtered and the second to the rows in the visual with countries filtered. The measure is placed in the visual and it looks like this</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2820" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.6.png" alt="" width="572" height="536" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.6.png 572w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.6-480x450.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 572px, 100vw" /></p>
<p>&nbsp;</p>
<p>This is exactly what we wanted and we can clearly see the difference between v2 and v4 measures. The v4 measure uses the v3 measure as a denominator in the <span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> function. And the denominator has <span class="Keyword" style="color: #035aca;">ALLSELECTED</span> ( Location[Continent] ) which removes filters from selected continents. We could have used <span class="Keyword" style="color: #035aca;">ALL</span>( Location[Continent] ) as well and achieved the same result as above but the difference is that when we select more than one Continent from a slicer it would not have worked. Let us do just that. We will select Europe and North America from the Continent slicer and see what the visual does</span></p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2821" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.7.png" alt="" width="820" height="339" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.7.png 820w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.7-480x198.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 820px, 100vw" /></p>
<p>The reason for using <span class="Parenthesis" style="color: #808080;"><span class="Keyword" style="color: #035aca;">ALLSELECTED</span> ( Location[Continent] ) is now clear. When we select &#8216;Europe&#8217; and &#8216;North America&#8217; from the Continent slicer we get the % revenue of Europe and North America of their combined total.</span></p>
<p>Let us add another twist to this. For the set up above what we wanted to show the export revenue for each country as the % of  ALL the counties in the selection regardless of the continent they are in. For ex: we want to know the % of United States as $9.7/$35.06. For this we define our final measure as below</p>
<p>&nbsp;</p>
<p>Export Revenue % v5 =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISINSCOPE</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], [Export Revenue % v3] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span>[Export Revenue ($)],<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue % v3], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>Here, in the second part of the IF statement in the denominator of the <span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> function we remove all filters from the selected countries which would give us the total of $35.06 for all the countries and the numerator would the export revenue for that particular country. The final visual looks like this </span></p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2822" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.8.png" alt="" width="820" height="339" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.8.png 820w, https://capstoneanalytics.com.au/wp-content/uploads/2022/07/How-to-write-DAX-5.8-480x198.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 820px, 100vw" /></p>
<p>You can see that the % of United States coal revenue for all the countries in Europe and North America is 27.7%</p>
<p>&nbsp;</p>
<h3><strong>Summary</strong></h3>
<p>In this fifth part of the series, we have seen how to use the ALL family of functions to calculate % of totals for various business requirements</p>
<blockquote><p>Any problem involving the calculation of % of total values</p></blockquote>
<ul>
<li>What is Australia&#8217;s share of global export revenue</li>
<li>What % of garments are manufactured in China ?</li>
<li>What is Amazon&#8217;s share of global electronics sales ?</li>
</ul>
<p>&nbsp;</p>
<p><em>Australia&#8217;s share of global export revenue=</em><br />
<span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span>[Export Revenue ($)],<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>When Continent is added as the top most hierarchy in a visual, to get the share of each country as the % of the Continent total</p>
<p><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISINSCOPE</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], <span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Export'[Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span>[Export Revenue % v2]<br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>When Continent is added as the top most hierarchy in a visual, to get the share of each country as the % of the selected Continents&#8217; total</p>
<p><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISINSCOPE</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue ($)], <span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Export'[Export Revenue ($)], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Continent] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span>[Export Revenue ($)],<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Export Revenue % v3], <span class="Keyword" style="color: #035aca;">ALLSELECTED</span><span class="Parenthesis" style="color: #808080;"> (</span> Location[Country] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-5-what-is-australias-share-of-global-export-coal-revenue/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to solve business problems using DAX &#8211; Part 4: How many sales orders are greater than $3000</title>
		<link>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-4-how-many-sales-orders-are-greater-than-3000/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-solve-business-problems-using-dax-part-4-how-many-sales-orders-are-greater-than-3000</link>
					<comments>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-4-how-many-sales-orders-are-greater-than-3000/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Sat, 04 Jun 2022 01:45:40 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Solve Business Problems]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2715</guid>

					<description><![CDATA[In Part 3 of the series, we talked about how to solve business problems when you want to filter a measure by attributes from the fact/dimension table and then evaluate an expression. In this series, we continue the conversation and this time we talk about how to filter the tables using numeric and date expressions [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-3-what-is-the-sales-amount-for-the-contoso-brand/">Part 3</a> of the series, we talked about how to solve business problems when you want to filter a measure by attributes from the fact/dimension table and then evaluate an expression. In this series, we continue the conversation and this time we talk about how to filter the tables using numeric and date expressions</p>
<h3></h3>
<h3><strong>The Business Problem &#8211; How many sales orders are greater than $3000</strong></h3>
<p>&nbsp;</p>
<p>Businesses are often interested in answering what is their given sales/tonnes/profit which is greater than a certain number for a given attribute. This is, so that they can isolate those orders/tonnes/projects and focus on what went right, targeted campaigns etc. Some questions along these lines</p>
<ul>
<li>How many excavators produced more than $1M tonnes of Irone Ore  ?</li>
<li>What is the average height of the class of children who are more than 10 years old ?</li>
<li>Which projects made a loss last quarter ?</li>
</ul>
<p>So coming back to the original question. This is an interesting one as this requires us to think carefully on how to use the filters. The Sales Amount field is only available in the Fact table, hence we need to filter the FactOnlineSales table to only include sales orders which are greater than $3000 as these are high value orders for the business. Ultimately the business wants to know the % of high value orders. The pattern then becomes</p>
<p><em>Sales Orders Greater Than 3000=</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] &gt; <span style="color: #ee7f18;">3000</span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result then becomes</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2735" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/How-to-write-DAX-4.1.png" alt="" width="378" height="192" /></p>
<p>&nbsp;</p>
<p>The pattern for the % high value orders becomes</p>
<p>&nbsp;</p>
<p><em>% of High Value Orders =</em><br />
<em><span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Sales Orders Greater Than 3000],</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result then becomes</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2744" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/How-to-write-DAX-4.2.png" alt="" width="378" height="204" /></p>
<p>So, only 2.3% of sales orders have sales greater than 300</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; How many customers made less than 50 purchases ?</strong></h3>
<p>This problem uses the similar pattern to the above but instead of using columns from the fact table it uses dimension table columns as a filter in the calculate function.</p>
<p>We first need to define the number of purchases</p>
<p>&nbsp;</p>
<p>Number of Purchases = <span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>We then define the final measure where we use the above measure to filter the customers from the DimCustomer table</p>
<p>Number of Customers with less than 50 purchases =<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Number of Purchases] &lt; <span class="Number" style="color: #ee7f18;">50</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>The result then becomes</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2795 size-full" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/How-to-write-DAX-4.4-e1653099006852.png" alt="" width="432" height="199" /></p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; What is the average amount spent by customers whose annual income is greater than $150K and who spent more than $10M across all years</strong></h3>
<p>In this pattern we will discuss multiple numeric filters and apply some of the logic we have seen in previous series. The patterns answers questions along these lines</p>
<ul>
<li>How many cars were sold in 2021 whose engine capacity is more than 2L and customers spent more than $50,000 per car ?</li>
<li>What were the loss making stores of last year who sold more than $1M items ?</li>
<li>How many projects made a profit in 2020 where they had less than 10 people working per project ?</li>
</ul>
<p>So lets talk high value customers. High value customers are those whose annual income is greater than $150,000 and who have spent more than $10M over the years. The business wants to know their average sales so that they can do some modelling and forecast how much more can these customers spend so that they can target their marketing campaigns on them. Astute readers will note that anyone who is on say $160K annual income will never be able to spend $10M on a particular stores(s). But knowing that this is a dummy dataset, we will ignore the absurdity of the data distribution and go ahead and solve the problem.</p>
<p>The patten then becomes</p>
<p>&nbsp;</p>
<p><em>Average Sales of High Value Customers =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span>DimCustomer[YearlyIncome] &gt; <span class="Number" style="color: #ee7f18;">150000</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] &gt; <span class="Number" style="color: #ee7f18;">10000000</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2745" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/How-to-write-DAX-4.3.png" alt="" width="372" height="243" /></p>
<h3><strong>Summary</strong></h3>
<p>In this fourth part of the series, we have seen how to filter fact tables by using a measure to filter dimension/fact tables. Use the following patterns to answer the following questions.</p>
<blockquote><p>Any problem involving the filtering measures in the fact table by iterating a measure across dimension/fact tables.</p></blockquote>
<ul>
<li>How many sales orders are greater than $3000 ?</li>
<li>Which projects made a loss last quarter ?</li>
<li>How many customers made less than 50 purchases ?</li>
</ul>
<p>&nbsp;</p>
<p>While iterating over a fact table use this pattern</p>
<p><em>Sales Orders Greater Than 3000=</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] &gt; <span style="color: #ee7f18;">3000</span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>While iterating over a dimension table use this pattern</p>
<p>Number of Customers with less than 50 purchases =<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Number of Purchases] &lt; <span class="Number" style="color: #ee7f18;">50</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<blockquote><p>Any problem involving the filtering measures in the fact table by a combination of filtering by dimension attributes and iterating a measure across dimension/fact tables.</p></blockquote>
<ul>
<li>How many customers under the age of 30 spend $50k in 2021 ?</li>
<li>How many accounts had accumulated less than $50k in interest where the annual income of customers was over $500k ?</li>
<li>How many stores had less than 50 employees and made a profit last financial year ?</li>
</ul>
<p>&nbsp;</p>
<p><em>Average Sales of High Value Customers in 2021 =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span>DimCustomer[YearlyIncome] &gt; <span class="Number" style="color: #ee7f18;">150000</span>, DimDate[CalendarYear] = 2021,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCustomer[CustomerKey] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] &gt; <span class="Number" style="color: #ee7f18;">10000000</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-4-how-many-sales-orders-are-greater-than-3000/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to solve business problems using DAX &#8211; Part 3: What is the sales amount for the Contoso Brand ?</title>
		<link>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-3-what-is-the-sales-amount-for-the-contoso-brand/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-solve-business-problems-using-dax-part-3-what-is-the-sales-amount-for-the-contoso-brand</link>
					<comments>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-3-what-is-the-sales-amount-for-the-contoso-brand/#comments</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Sat, 12 Feb 2022 18:14:20 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Solve Business Problems]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2687</guid>

					<description><![CDATA[In the second part of the series on how to solve business problems using DAX we looked at some patterns for calculating averages different grains in the model. In this series we will look at patterns where we need sales amount filtered for a value(s) of an column of the dimension/fact table(s). Think of this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In the second part of the series on how to solve business problems using DAX we looked at some patterns for calculating averages different grains in the model. In this series we will look at patterns where we need sales amount filtered for a value(s) of an column of the dimension/fact table(s). Think of this pattern as equivalent to applying a WHERE clause to a SQL query. The WHERE clause can  be applied either on a dimension column or on a fact column</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Sales Amount for Contoso Brand</strong></h3>
<p>&nbsp;</p>
<p>A common business problem is to slice and dice Facts by their Dimensional attributes. A problem like &#8220;What is the sales amount for Brand XXX&#8221; is a common one. Similar examples are like the following</p>
<ul>
<li>What is the tonnes mined by a CAT excavator ?</li>
<li>What is the total units manufactured in 2021 ?</li>
<li>What are the expenses incurred by external consultants ?</li>
</ul>
<p>&nbsp;</p>
<p>Coming back to the problem of &#8220;What is the sales amount for Contoso Brand ?&#8221;, we need to filter the [Total Sales] measure where Brand = &#8216;Contoso&#8217;. The pattern is as follows</p>
<p>&nbsp;</p>
<p><em>Contoso Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Total Sales], DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result is as follows</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2693" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-3.0.png" alt="" width="434" height="260" /></p>
<p>&nbsp;</p>
<p>Internally, the DAX measure is  written as</p>
<p>&nbsp;</p>
<p><em>Contoso Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct[BrandName] <span class="Parenthesis" style="color: #808080;">)</span>, DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This is important to know, as many a times I see the measure written as below.</p>
<p>&nbsp;</p>
<p><em>Contoso Sales DO NOT USE =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct, DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>While technically this measure produces the same result as the first one, there are two problems with it.</p>
<ol>
<li>Instead of materialising just one column, BrandName, the entire table DimProduct may be materialised (depending on the version of Analysis Services you are running) which can make the measure slower to execute</li>
<li>The measure will return blank when a value apart from &#8216;Contoso&#8217; is selected from the BrandName column slicer in the report. This may not be the result needed as in most cases we always need to display &#8216;Contoso Sales&#8217; regardless of what value is selected from the BrandName column slicer</li>
</ol>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Sales Amount for Contoso Brand AND Silver Colour</strong></h3>
<p>&nbsp;</p>
<p>Businesses often want to report on metrics which are filtered to values from multiple entities in the dimension tables. The questions can take the following examples</p>
<ul>
<li>What is the sales amount for Contoso Brand and Silver Colour ?</li>
<li>What is the total tonnes for CAT excavator in 2021 ?</li>
<li>What is the expenses incurred by external consultants in the last quarter ?</li>
</ul>
<p>The entities can come from the same or different table. The generic pattern when the AND condition is involved becomes the following for the problem &#8220;What is the sales amount for Contoso Brand and Silver Colour&#8221; becomes</p>
<p><em>Contoso Silver Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span>DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        ,</span> DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>When the entities are from the same table which is the case in the above example this can also be written as</p>
<p><em>Contoso Silver Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span>DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        &amp;&amp;</span> DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result is as follows</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2696" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-3.1.png" alt="" width="426" height="232" /></p>
<p>&nbsp;</p>
<p>It is pertinent to note that the result is a subset of Contoso Sales as we want the Total Sales where BrandName = &#8216;Contoso&#8217; AND ColorName = &#8216;Silver&#8217;. We can keep adding entities from the same table by appending &#8216;&amp;&amp;&#8217; to them or from different tables by appending &#8216;,&#8217; to them.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Sales Amount for Contoso Brand OR Silver Colour</strong></h3>
<p>&nbsp;</p>
<p>Sometimes the business problem is to determine the sales amount which involves an OR condition. Businesses want to know the sales amount where Brand is &#8216;Contoso&#8217; or Colour is &#8216;Silver&#8217;. The pattern then becomes</p>
<p>&nbsp;</p>
<p><em>Contoso OR Silver Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span>DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        </span>|| DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result then becomes</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2698" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-3.2.png" alt="" width="362" height="223" /></p>
<p>&nbsp;</p>
<p>Note that the &#8216; || &#8216; operator can only be used if we are filtering attributes from the same table. If you are using different you cannot use it, as it equates to using an AND operation and hence you should use &#8216; , &#8216; instead.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Sales Amount for Brand Not Equal to Contoso OR Colour Not Equal to </strong><strong>Silver</strong></h3>
<p>&nbsp;</p>
<p>Sometimes the business problem is to calculate sales which does not equal values from one or more entities. In this case instead of focusing on the logic for the negation, focus on the logic for the reverse which is easier to do and then wrap it around the NOT operator. The pattern for the problem &#8220;What is the sale amount for brand not equal to Contoso or colour not equal to Silver ?&#8221; becomes</p>
<p>&nbsp;</p>
<p><em>NOT Contoso OR Silver Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        </span>|| DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The result then becomes</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2700" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-3.3.png" alt="" width="375" height="210" /></p>
<p>&nbsp;</p>
<p>How can we validate this result ? We know that the total sales is 2.72bn. We also know that the sales for &#8220;sales amount when brand is Contoso OR Color is Silver&#8221; is 1.06bn. So the difference of the two (2.72 &#8211; 1.06 = 1.66) should be the negation which is what the above measure gives.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Average Sales Amount for Brand Not Equal to Contoso OR Colour Not Equal to </strong><strong>Silver</strong></h3>
<p>&nbsp;</p>
<p>What if we are interested in the Average Sales Amount by Sales Order but only for brands which are not equal to Contoso OR colour is not equal to Silver. We use the same patterns as above but instead of [Total Sales] we substitute it with the [Average Sales by Sales Order]. For clarity we will define the previous measure inside CALCULATE but you could define it as a measure on its own and call it inside CALCULATE.</p>
<p>&nbsp;</p>
<p><em>Average Sales Amount for Brand Not Equal to Contoso OR Colour Not Equal to Silver =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        </span>|| DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>The result then becomes</p>
<p><img loading="lazy" decoding="async" class=" wp-image-2723 alignleft" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-3.4.png" alt="" width="522" height="239" /></p>
<p>&nbsp;</p>
<h3></h3>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3><strong>Summary</strong></h3>
<p>In this third part of the series, we have seen how to use the WHERE equivalent of a SQL query or SUMIFS, COUNTIFS, AVERAGEIFS of Excel in DAX. Use the following patterns to answer the following questions.</p>
<blockquote><p>Any problem involving the filtering measures in the fact table by one or many dimensional/fact table attributes and calculating totals</p></blockquote>
<ul>
<li>What is the tonnes mined by a CAT excavator ?</li>
<li>What is the sales for Contoso Brand and Silver Colour ?</li>
<li>What are the expenses incurred by external consultants or internal consultants ?</li>
</ul>
<p>&nbsp;</p>
<p style="padding-left: 40px;"><em>Contoso Sales and Silver Colour =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Total Sales], DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span> , DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p style="padding-left: 40px;"><em>Contoso Sales or Silver Colour =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Total Sales], DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span>  || DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>If you want the negation of the above measure</p>
<p>&nbsp;</p>
<p style="padding-left: 40px;"><em>NOT Contoso OR Silver Sales =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span>[Total Sales],</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span></em><br />
<em><span class="indent8">        </span>|| DimProduct[ColorName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Silver&#8221;</span> <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<blockquote><p>Any problem involving the filtering measures in the fact table by one or many dimensional/fact table attributes and calculating totals</p></blockquote>
<ul>
<li>What is the average daily sales for Contoso Brand in 2008</li>
<li>What is the average monthly tonnes mined by CAT excavator in Mine A1</li>
<li>What are the average quarterly expenses incurred by external consultants last year ?</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="padding-left: 40px;"><em>Average daily sales for Contoso Brand in 2008 =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimDate[Datekey] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span>DimProduct[BrandName] = <span class="StringLiteral" style="color: #d93124;">&#8220;Contoso&#8221;</span>,</em><br />
<em><span class="indent4">    </span>DimDate[CalendarYear] = <span class="Number" style="color: #ee7f18;">2008</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/how-to-solve-business-problems-using-dax-part-3-what-is-the-sales-amount-for-the-contoso-brand/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to solve business problems using DAX &#8211; Part 2: What is the average sales amount by store ?</title>
		<link>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-2-what-is-the-average-sales-amount-by-store/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-solve-problems-using-dax-part-2-what-is-the-average-sales-amount-by-store</link>
					<comments>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-2-what-is-the-average-sales-amount-by-store/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Tue, 08 Feb 2022 13:26:18 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Solve Business Problems]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2669</guid>

					<description><![CDATA[In Part 1 of the series, we looked at some patterns to solve business problems which involved calculating total sales, maximum discount, unique products sold etc. In this Part, we will look at some patterns which involve calculating averages and also discuss some common pitfalls. &#160; The Business Problem &#8211; Average Sales &#160; A common [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-i-what-is-the-total-sales-amount/">Part 1</a> of the series, we looked at some patterns to solve business problems which involved calculating total sales, maximum discount, unique products sold etc. In this Part, we will look at some patterns which involve calculating averages and also discuss some common pitfalls.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Average Sales</strong></h3>
<p>&nbsp;</p>
<p>A common business problem is to determine the average sales. Some other problems along the same lines</p>
<ul>
<li>What is the average rainfall ?</li>
<li>What is the average temperature ?</li>
<li>What is the average queue time ?</li>
</ul>
<p>&nbsp;</p>
<p>Averages can be tricky to compute in Power BI. For an average we need a numerator and a denominator. However, in Power BI we have functions to calculate averages and we only need to specify the column over which the average is performed. Coming back to our model, the FactOnlineSales table is at the granularity of SalesOrderLineNumber. This means that for every SalesOrder we can have multiple items which have thier own SalesOrderLineNumber. So when we say &#8220;Give me average sales amount&#8221; do we mean &#8220;average sales by sales order line number&#8221; or &#8220;average sales by sales order&#8221; ? Most likely we are interested in average sales by sales order. And they use different formulae. If you want to calculate &#8220;average sales by sales order line number&#8221; we just use the AVERAGE function over the SalesOrderLineNumber column</p>
<p>&nbsp;</p>
<p><em>Average Sales Amount Per Sales Order Line Number = <span class="Keyword" style="color: #035aca;">AVERAGE</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2673" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.0.png" alt="" width="499" height="267" /></p>
<p>In order to calculate &#8220;average sales by sales order&#8221; we need to use the AVERAGEX function which is an iterator. We know that we need the average sales for SalesOrderNumber, hence we use it in the first argument of AVERAGE and the pattern becomes</p>
<p>&nbsp;</p>
<p><em>Average Sales Amount Per Sales Order = <span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesOrderNumber] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2674" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.1.png" alt="" width="467" height="257" /></p>
<p>&nbsp;</p>
<p>We can see that the Average Sales Amount Per Sales Order is greater than Average Sales Amount Per Sales Order Line Number. This makes sense as the sales order amount is greater than its sales order line number amount.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; Average Sales Per Store</strong></h3>
<p>Now lets discuss how to solve the problem &#8220;What is the average sales amount per store&#8221;. For this, we use the same pattern as above</p>
<p>&nbsp;</p>
<p><em>Average Sales Amount Per Store = <span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following results</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-2676" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.2.png" alt="" width="395" height="231" /></p>
<p>&nbsp;</p>
<p><span class="indent4">Most of the time, businesses are not interested in a single number for &#8220;Average sales amount by store&#8221; but they are interested to see it in a total sales by store bar chart as a line so that they can visualise which stores have sales above/below average. The pattern for this involves using CALCULATE and ALL functions and it looks like this. The ALL is needed to remove the filter context from the StoreName column in the bar chart.</span></p>
<p>&nbsp;</p>
<p><em>Average Sales Amount Per Store =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p><span class="indent4"> The bar chart looks like this for the current model</span></p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2677" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.3.png" alt="" width="800" height="541" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.3.png 800w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.3-480x325.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 800px, 100vw" /></p>
<p>&nbsp;</p>
<p>Now what if we dont have the column &#8216;SalesAmount&#8217; in the model ? We cannot use the above pattern to calculate Average Sales. We need to use a pattern which first creates a virtual table in which we calculate a new column by multiplying the columns SalesQuantity and UnitPrice and subtracting any DiscountAmount and then iterating over that table to get the average sales. The pattern looks like this</p>
<p><em>Average Sales Amount Per Store =</em><br />
<em><span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">t1</span> =</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ADDCOLUMNS</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SUMMARIZE</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales, DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;TotalSales&#8221;</span>,</em><br />
<em><span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SUMX</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="indent4">    </span>FactOnlineSales,</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="indent4">    </span>FactOnlineSales[SalesQuantity] * FactOnlineSales[UnitPrice] &#8211; FactOnlineSales[DiscountAmount]</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span>FactOnlineSales[SalesQuantity] &gt; <span class="Number" style="color: #ee7f18;">0</span></em><br />
<em><span class="indent8">        </span><span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Keyword" style="color: #035aca;">RETURN</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Variable" style="color: #49b0af;">t1</span>, [TotalSales] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>This pattern is longer and not simple. Hence it is advisable to calculate the column &#8216;SalesAmount&#8217; in the Fact table in the source so that we can easily retrieve it to calculate &#8216;Average Sales&#8217; and use easier patterns.</p>
<p>&nbsp;</p>
<h3><strong>SUMMARY</strong></h3>
<p>In this second part of the series on how to solve business problems using DAX we have covered business problems which involve averages and provided DAX formulas for each of them. Use the following patterns to answer the following questions.</p>
<blockquote><p>Any problem involving averaging fact table columns in the same grain as in the model and if the questions are like the following</p></blockquote>
<ul>
<li>What is the average sales amount by sales order line number ?</li>
<li>What is the average temperature ?</li>
<li>What is the average queue time ?</li>
</ul>
<p><em>Average Sales Amount Per Sales Order Line Number = <span class="Keyword" style="color: #035aca;">AVERAGE</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<blockquote><p>Any problem involving averaging fact table columns by dimension/fact table entities at a higher grain than the column to be averaged</p></blockquote>
<ul>
<li>What is the average sales amount per store ?</li>
<li>What is the average rainfall per year ?</li>
<li>What is the average sales calls per region</li>
</ul>
<p><em>Average Sales Amount Per Store = <span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>If you want to use this as a line in total sales amount bar chart, use this pattern</p>
<p><em>Average Sales Amount Per Store =</em><br />
<em><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>, [Total Sales] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ALL</span><span class="Parenthesis" style="color: #808080;"> (</span> DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>If you have to calculate &#8216;SalesAmount&#8217; column in a virtual pattern because its not available in the model, use this pattern</p>
<p><em>Average Sales Amount Per Store =</em><br />
<em><span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">t1</span> =</em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ADDCOLUMNS</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SUMMARIZE</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales, DimStore[StoreName] <span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;TotalSales&#8221;</span>,</em><br />
<em><span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SUMX</span><span class="Parenthesis" style="color: #808080;"> (</span></em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="indent4">    </span>FactOnlineSales,</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="indent4">    </span>FactOnlineSales[SalesQuantity] * FactOnlineSales[UnitPrice] &#8211; FactOnlineSales[DiscountAmount]</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span>,</em><br />
<em><span class="indent8">        </span><span class="indent8">        </span>FactOnlineSales[SalesQuantity] &gt; <span class="Number" style="color: #ee7f18;">0</span></em><br />
<em><span class="indent8">        </span><span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></em><br />
<em><span class="Keyword" style="color: #035aca;">RETURN</span></em><br />
<em><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">AVERAGEX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Variable" style="color: #49b0af;">t1</span>, [TotalSales] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-2-what-is-the-average-sales-amount-by-store/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to solve business problems using DAX &#8211; Part 1: What is the total/max/min sales amount</title>
		<link>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-i-what-is-the-total-sales-amount/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-solve-problems-using-dax-part-i-what-is-the-total-sales-amount</link>
					<comments>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-i-what-is-the-total-sales-amount/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Mon, 07 Feb 2022 11:52:49 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Solve Business Problems]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2645</guid>

					<description><![CDATA[Welcome to the first part of the series on &#8220;How to solve problems using DAX&#8221;. I spent a lot of time last year posting DAX challenges on LinkedIn which not only covered DAX functions such as CALCULATE, FILTER, TOPN, RANKX but also concepts such as context transition and expanded tables. The challenges were not only [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Welcome to the first part of the series on &#8220;How to solve problems using DAX&#8221;. I spent a lot of time last year posting DAX challenges on LinkedIn which not only covered DAX functions such as CALCULATE, FILTER, TOPN, RANKX but also concepts such as context transition and expanded tables. The challenges were not only well received by the community but they also helped me to fill the gaps in my knowledge of DAX.</p>
<p>So this year I wanted to expand on that by starting a series which would talk about how to use the various concepts and functions of DAX to solve business problems. Its one thing to know the inner workings of DAX but even with all the knowledge, sometimes DAX users fail to apply the correct functions while solving problems. This results in poorly written code which is not performant and worse, gives incorrect results. Hence the purpose of this blog.</p>
<p>I hope to standardize some patterns which can be used to answer various business problems like &#8221; What is the total sales of all products for all years across all regions&#8221;, &#8220;How many units of Product A were manufactured in 2021&#8243;, &#8221; What are the top 10 Stores in Category A for Size P&#8221; etc. The focus is not on understanding of the DAX functions per se (it is assumed that the reader has a very good understanding of the most common DAX functions) but rather, given a business problem how to write effective DAX that is not only readable and performant but which also answers the question correctly. At the end of each Part, a summary pattern  will be given which can be used to answer the business problem posed at the start of the blog.</p>
<p>Each part of the series will be dedicated to a business problem and various DAX formulae will be provided to answer the problem. Where possible, a often used but wrong solution will also be provided and explanation given as to why that solution is incorrect.</p>
<p>&nbsp;</p>
<h3><strong>The Data Model</strong></h3>
<p>&nbsp;</p>
<p>We will be using the Contoso database imported into Power BI as our data model. Contoso is a demo database provided by Microsoft which has a few fact tables on retail sales and dimension tables like Customer, Product, Store etc. We will be using FactOnlineStore as our Fact table and DimCustomer, DimDate, This is a typical star schema which is the recommended model for Power BI reports. If you do not have a star schema for your reports make sure to convert them to a star schema before continuing with this series. The model looks like this</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2649" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX.png" alt="" width="1392" height="850" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX.png 1392w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-1280x782.png 1280w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-980x598.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-480x293.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1392px, 100vw" /></p>
<h3><strong>The Business Problem &#8211; Total Sales</strong></h3>
<p>&nbsp;</p>
<p>We will start with the most basic question asked in a Power BI report. This generally goes like this</p>
<ul>
<li>What is the total sales</li>
<li>What is the total tonnes produced</li>
<li>What is the total number of units manufactured</li>
</ul>
<p>This can be answered by using the SUM function like this</p>
<p>&nbsp;</p>
<p><em>Total Sales = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>The measure [Total Sales] can be used in a card, line chart, bar chart etc. If we want to use it in a card drag a card visual onto a blank page and drag the measure under Values.</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2667" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-2.png" alt="" width="407" height="259" /></p>
<p>If you want to use it in a line chart or a bar chart you can use the appropriate fields from any of the dimension tables. A typical line chart and bar chart with this measure looks like this</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2703" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-1.2.png" alt="" width="955" height="754" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-1.2.png 955w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-1.2-480x379.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 955px, 100vw" /></p>
<p>Thus we can see that, from a basic pattern like SUM we can produce multiple visualisation from a start schema model and gain valuable insights</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; What is the maximum/minimum discount given ?</strong></h3>
<p>&nbsp;</p>
<p>A closely related business problem goes like this</p>
<ul>
<li>What is the maximum/minimum discount given ?</li>
<li>What is the highest/lowest temperature ?</li>
<li>What is the maximum/minimum sales calls made ?</li>
</ul>
<p>&nbsp;</p>
<p>A business would be interested to know what is the most/least amount of discount given for a sales order in order to better understand their profit margins. These can be answered using the MAX/MIN functions. To get the maximum discount amount in our model we need to figure out which field to use. in the model the DiscountQuantity field gives the discount that is given to any sales order. We can use this field to get the maximum discount given</p>
<p>&nbsp;</p>
<p><em>Maximum Discount = <span class="Keyword" style="color: #035aca;">MAX</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[DiscountAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result in the model</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2659" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-4.png" alt="" width="377" height="232" /></p>
<p>In the same way we can determine the minimum discount given</p>
<p>&nbsp;</p>
<p><em>Minimum Discount = <span class="Keyword" style="color: #035aca;">MIN</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[DiscountAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result in the model</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2660" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-5.png" alt="" width="343" height="274" /></p>
<p>Hence whenever we are dealing with determining the maximum/minimum values of a column we need to use the MAX/MIN over the column. In future parts we will look at some more complex business problems where we will have to determine the maximum/minimum at a grain higher than that of the model.</p>
<p>&nbsp;</p>
<h3><strong>The Business Problem &#8211; What is the unique number of products sold ?</strong></h3>
<p>&nbsp;</p>
<p>In the previous section we looked at summing sales/quantities and determining the maximum/.minimum of a field, In this section we will look at a common business problem of the likes of</p>
<ul>
<li>What is the unique number of products sold</li>
<li>How many months worth of data does the model contain ?</li>
<li>How many unique customers made purchases ?</li>
</ul>
<p>&nbsp;</p>
<p>Each of these questions can be answered by using the DISTINCTCOUNT function. So in our model if we have to determine how many unique products have been sold we need to look at the FactOnlineSales table and find the column which is in a many-to-one relationship with the DimProduct table. We have exactly such a column and its called ProductKey. Since each product could have been bought multiple times we need to find the distinct count of the ProductKey field from the FactOnlineSales table.</p>
<p>&nbsp;</p>
<p><em>Unique Products Sold = <span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[ProductKey] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result in the model</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2661" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-6.png" alt="" width="346" height="227" /></p>
<p>A wrong solution to the problem is to count the number of Products in the DimProduct table. This may not give you the right answers as there might be products for which there have been no sales recorded. For educational purposes the formula is given but the reader is advised not to use it.</p>
<p>&nbsp;</p>
<p><em>Unique Products Sold WRONG = <span class="Keyword" style="color: #035aca;">COUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimProduct[ProductKey] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result in the model</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2662" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-7.png" alt="" width="440" height="253" /></p>
<p>We see that the number of products in the model is not equal to the unique products sold. The fact that they only differ by 1 is due to the demo model being used. In real life models the difference would be higher.</p>
<p>Let&#8217;s tackle a slightly dificult problem and answer the question &#8220;How many months worth of data is present in the model&#8221; ?. Ideally we would have liked a CalendarMonth column in the format yyyymm to be included in the FactOnlineSales table so that we could do a DISTINCTCOUNT over it and get the results. But the CalendarMonth column is only present in the DimDate table and there is no point in reproducing it in the Fact table just to answer this question. So then how do we calculate it ? We need to use the CALCULATE function and also use the concepts of Expanded Tables. If you need to learn these concepts in detail please go though the articles on www.SQLBI.com for indepth explanations of those concepts. For our purpose we will define this measure.</p>
<p>&nbsp;</p>
<p><em>Months of Data Available = <span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimDate[CalendarMonth] <span class="Parenthesis" style="color: #808080;">)</span>, FactOnlineSales <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>This gives the following result in the model</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2663" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/How-to-write-DAX-8.png" alt="" width="392" height="245" /></p>
<p>This works because when you put a Fact table in the second argument of CALCULATE, it creates a left join with all the dimension tables joined to it whereby &#8216;expanding&#8217; the Fact table. Since the left join contains all the rows of the Fact table, the columns of the dimension table which are joined to this expanded Fact table also contain the same rows. Hence when you do a DISTINCTCOUNT over the CalendarMonth column from the DimDate you only get months for which there is sales data in the model.</p>
<p>&nbsp;</p>
<h3><strong>SUMMARY</strong></h3>
<p>In this first part of the series on how to solve business problems using DAX we have covered some of the most basic business problems covered in a Power BI report and provided DAX formulas for each of them. Use the following patterns to answer the following questions.</p>
<blockquote><p>Any problem involving summing sales, quantity, measurement and if the questions are like the following</p></blockquote>
<ul>
<li>What is the total sales</li>
<li>What is the total tonnes produced</li>
<li>What is the total number of units manufactured</li>
</ul>
<p style="padding-left: 40px;"><em>Total Sales = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[SalesAmount] <span class="Parenthesis" style="color: #808080;">) </span></em></p>
<p>&nbsp;</p>
<blockquote><p>Any problem involving calculating maximum/minimum over a column and if the questions are like the following</p></blockquote>
<ul>
<li>What is the maximum/minimum discount given ?</li>
<li>What is the highest/lowest temperature ?</li>
<li>What is the maximum/minimum sales calls made ?</li>
</ul>
<p style="padding-left: 40px;"><em>Maximum Discount = <span class="Keyword" style="color: #035aca;">MAX</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[DiscountAmount] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<blockquote><p>Any problem involving calculating the unique values of a column and if the questions are like the following</p></blockquote>
<ul>
<li>What is the unique number of products sold</li>
<li>How many months worth of data does the model contain ?</li>
<li>How many unique customers made purchases ?</li>
</ul>
<p style="padding-left: 40px;"><em>Unique Products Sold = <span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> FactOnlineSales[ProductKey] <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>If the column to be used is in the dimension table use this pattern</p>
<p>&nbsp;</p>
<p style="padding-left: 40px;"><em>Months of Data Available =<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">DISTINCTCOUNT</span><span class="Parenthesis" style="color: #808080;"> (</span> DimDate[CalendarMonth] <span class="Parenthesis" style="color: #808080;">)</span>, FactOnlineSales <span class="Parenthesis" style="color: #808080;">)</span></em></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/how-to-solve-problems-using-dax-part-i-what-is-the-total-sales-amount/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Visualising top city sales % for a region</title>
		<link>https://capstoneanalytics.com.au/visualising-top-city-sales-for-a-region/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=visualising-top-city-sales-for-a-region</link>
					<comments>https://capstoneanalytics.com.au/visualising-top-city-sales-for-a-region/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Tue, 01 Feb 2022 04:43:13 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2637</guid>

					<description><![CDATA[This post is inspired by a blog in which the author showcased the visualisation of % top city sales for a region in Tableau. I thought the solution provided was cumbersome so decided to visualise it in Power BI. It turns out that the DAX for this is straightforward but the visualisation was tricky as [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This post is inspired by a blog in which the author showcased the visualisation of % top city sales for a region in Tableau. I thought the solution provided was cumbersome so decided to visualise it in Power BI. It turns out that the DAX for this is straightforward but the visualisation was tricky as I had to use two visuals to convey all the information. In this blog I will show how to do it.</p>
<p>The data model has two tables, Orders and Region. Each region has many cities within it, The problem statement is to determine the city with the top sales % and visualise it. So lets start with the DAX first. The first measure to be defined is SalesAmount</p>
<p>SalesAmount = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> Orders[Sales] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Next we define a measure which calculates the sales of the top city for each region. For this, firstly we will define a measure which will calculate the city with the most sales</p>
<p>Top City =<br />
<span class="Keyword" style="color: #035aca;">TOPN</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Number" style="color: #ee7f18;">1</span>, <span class="Keyword" style="color: #035aca;">VALUES</span><span class="Parenthesis" style="color: #808080;"> (</span> Region[City] <span class="Parenthesis" style="color: #808080;">)</span>, [SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Top City Sales is defined as</p>
<p>Top City Sales =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">topcity</span> = [Top City]<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">result</span> =<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SUMX</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">FILTER</span><span class="Parenthesis" style="color: #808080;"> (</span> Region, Region[City] = <span class="Variable" style="color: #49b0af;">topcity</span> <span class="Parenthesis" style="color: #808080;">)</span>, [SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">   <span class="Variable" style="color: #49b0af;">result</span></span></p>
<p>Next we define the Top City Sales %</p>
<p>Top City Sales % =<br />
<span class="Keyword" style="color: #035aca;">DIVIDE</span><span class="Parenthesis" style="color: #808080;"> (</span> [Top City Sales], [SalesAmount], <span class="Number" style="color: #ee7f18;">0</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Finally we define a measure which gives the difference between SalesAmout and TopCitySales</p>
<p>Sales Amount Diff = [SalesAmount] &#8211; [Top City Sales]</p>
<p>Next we visualise it. Drag the 100% Stacked Bar chart visual into an open canvas and drag Country into Axis and Top City Sales and Sales Amount Diff under Values. Formatting Top City Sales as Blue and Sales Amount Diff as grey and turning on Data Labels for Top City Sales, we get the following visual</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2641" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-1.png" alt="" width="670" height="545" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-1.png 670w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-1-480x391.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 670px, 100vw" /></p>
<p>Since India has the largest Sales it is shown as first and China is second and so on. You can also see that the Top City Sales for India is 72.6% and the country with the highest sales of its top city is Canada at 98.2%. But Canada has lower sales hence its not at the top of the chart. What we want is to sort this visual by the top city sales % measure so that the chart will be ordered in descending order of top city sales %. For this to be achieved, we drag Top City Sales % measure under Tooltips. We also drag the measure Top City under Tooltips. Using the three dots at the top right corner of the chart we sort the Axis in descending order by Top City Sales % and we get this chart</p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-2642" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-2.png" alt="" width="729" height="551" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-2.png 729w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-2-480x363.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 729px, 100vw" /></p>
<p>This is already looking good. Canada is now on top and New Zealand is at the bottom. But by just looking at this visual we do not get any information on which are the top cities for each region nor do we get any information on Sales Amount for the region and the cities. in order to achieve this we drag a Table visual into the same canvas and drag Country, SalesAmount, Top City, Top City Sales, and Top City Sales % under Values. We then conditionally format Sales Amount and Top City Sales (Under Values right Click on each of those measures  and select Conditional formatting -&gt; Data bars and choose the required colours). We then place the Table visual beside the 100% stacked bar chart and ensure that the rows are aligned. It should look like this</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2643" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-3.png" alt="" width="1051" height="439" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-3.png 1051w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-3-980x409.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/02/TOP-City-Sales-3-480x200.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1051px, 100vw" /></p>
<p>We now get the complete picture of the cities with the highest sales for each region and also their Sales Amount and % of the total sales</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/visualising-top-city-sales-for-a-region/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Executive dashboard using calculation groups, date interval table ,and disconnected tables</title>
		<link>https://capstoneanalytics.com.au/executive-dashboard-using-calculation-groups-date-interval-table-and-disconnected-tables/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=executive-dashboard-using-calculation-groups-date-interval-table-and-disconnected-tables</link>
					<comments>https://capstoneanalytics.com.au/executive-dashboard-using-calculation-groups-date-interval-table-and-disconnected-tables/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Thu, 25 Feb 2021 06:46:27 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Calculation Groups]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[Date Interval]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Disconnected tables]]></category>
		<category><![CDATA[Executive Dashboard]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2538</guid>

					<description><![CDATA[Calculations groups are a collection of calculation items which are defined as base measures to easily calculate (mostly) time intelligence functions such as YTD, MTD, QTD without explicity writing such measures for each metric in the model. You can have multiple calculation groups in your model as well, though due precautions need to be taken. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Calculations groups are a collection of calculation items which are defined as base measures to easily calculate (mostly) time intelligence functions such as YTD, MTD, QTD without explicity writing such measures for each metric in the model. You can have multiple calculation groups in your model as well, though due precautions need to be taken. In this post we will see how to combine calculation groups, date interval table and disconnected table to produce powerful executive style dashboards.</p>
<p>Before we define calculated groups lets define some measures which we will use later</p>
<p>Total Sales = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> FactSales[SalesAmount] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Total Order Quantity = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> FactSales[OrderQuantity] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Total Tax Amount = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> FactSales[TaxAmt] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>0_CurrentYear = <span class="Keyword" style="color: #035aca;">YEAR</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">NOW</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span> + <span class="Number" style="color: #ee7f18;">10</span> / <span class="Number" style="color: #ee7f18;">24</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>We can define calculated groups using <a href="https://tabulareditor.com/">Tabular Editor</a> (TE). In our favourite model we connect to TE and define a new calculated group called TimeIntelligence and define three calculation items YTD, QTD, MTD as follows</p>
<p>YTD:<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATESYTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>QTD:<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATESQTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>MTD:<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATESMTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span></p>
<p>We rename the column from Name to TimeCalculation and save the model.</p>
<p>We want to visualise the data now. In a blank report we create a line chart with DateID in the X axis and [Total Sales] under values. We then create a slicer with TimeCalculaion as the Field. The report looks like this when we start changing values in the slicer.</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2538-1" width="1080" height="675" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210225_163809.mp4?_=1" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210225_163809.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210225_163809.mp4</a></video></div>
<p>&nbsp;</p>
<p>Not what we had in mind. What&#8217;s happening is when we choose YTD from the slicer we get the YTD lines for all the four years in the model (2018,2019,2020,2021) and similarly when choose QTD and MTD we get the respective &#8220;To Date&#8221; values for each quarter and month in the model. What we actually need is to give us a report giving YTD, QTD, MTD values for the current period. What we also want in another chart is to give us the yearly, quaterly, monthly values when we choose the appropriate values in the slicers. We achieve this by creating a DateInterval table. There are many ways to achieve this and one way is to run a SQL script like this. I&#8217;m running this on an Azure instance.</p>
<p><span style="color: blue;">DECLARE</span></p>
<p><span style="color: #8000ff;">@CurrentDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>CAST</i></span><span style="color: maroon;">(</span><span style="color: #ff0080;"><b>SYSDATETIMEOFFSET</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: maroon;">AT</span> <span style="color: maroon;">TIME</span> <span style="color: maroon;">ZONE</span> <span style="color: red;">&#8216;AUS Eastern Standard Time&#8217;</span> <span style="color: blue;">AS</span> <span style="color: black;"><i>DATE</i></span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">DECLARE</span></p>
<p><span style="color: #8000ff;">@StartYearDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@EndYearDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: maroon;">)</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@StartMonthDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@EndMonthDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: #ff0080;"><b>EOMONTH</b></span><span style="color: maroon;">(</span><span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@StartQuarterDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@EndQuarterDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@PreviousYearStartDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@PreviousYearEndDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">yy</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: maroon;">)</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@StartPreviousMonth</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: black;">32</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@EndPreviousMonth</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@Start14DaysPrevious</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">day</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">day</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">14</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@End14DaysPrevious</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">day</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">day</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span></p>
<p><span style="color: silver;">,</span><span style="color: #8000ff;">@PreviousYearStartQuarterDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">YEAR</span><span style="color: silver;">,</span><span style="color: silver;">&#8211;</span><span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@PreviousYearStartMonthDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">YEAR</span><span style="color: silver;">,</span><span style="color: silver;">&#8211;</span><span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">month</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@CurrentDate</span><span style="color: maroon;">)</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">DECLARE</span></p>
<p><span style="color: #8000ff;">@PreviousYearEndQuarterDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">qq</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartQuarterDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><br />
<span style="color: silver;">,</span><span style="color: #8000ff;">@PreviousYearEndMonthDate</span> <span style="color: black;"><i>DATE</i></span> <span style="color: silver;">=</span> <span style="color: #ff0080;"><b>EOMONTH</b></span><span style="color: maroon;">(</span><span style="color: #8000ff;">@PreviousYearStartMonthDate</span><span style="color: maroon;">)</span> <span style="color: silver;">;</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartYearDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@EndYearDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartYearDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;YTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">1</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearEndDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;YTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">1</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartQuarterDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@EndQuarterDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartQuarterDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;QTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">2</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartQuarterDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearEndQuarterDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartQuarterDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;QTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">2</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartPreviousMonth</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@EndPreviousMonth</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartPreviousMonth</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;Last Month&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">3</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartMonthDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@EndMonthDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@StartMonthDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;MTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">4</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartMonthDate</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearEndMonthDate</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@PreviousYearStartMonthDate</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;MTD&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">4</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p><span style="color: blue;">UNION</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: blue;">TOP</span> <span style="color: maroon;">(</span><span style="color: fuchsia;"><i>DATEDIFF</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@Start14DaysPrevious</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@End14DaysPrevious</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: maroon;">)</span> <span style="color: maroon;">Dates</span> <span style="color: silver;">=</span> <span style="color: fuchsia;"><i>DATEADD</i></span><span style="color: maroon;">(</span><span style="color: maroon;">DAY</span><span style="color: silver;">,</span> <span style="color: #ff0080;"><b>ROW_NUMBER</b></span><span style="color: maroon;">(</span><span style="color: maroon;">)</span> <span style="color: blue;">OVER</span> <span style="color: maroon;">(</span><br />
<span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">a</span><span style="color: silver;">.</span><span style="color: maroon;">object_id</span><br />
<span style="color: maroon;">)</span> <span style="color: silver;">&#8211;</span> <span style="color: black;">1</span><span style="color: silver;">,</span> <span style="color: #8000ff;">@Start14DaysPrevious</span><span style="color: maroon;">)</span><br />
<span style="color: silver;">,</span><span style="color: red;">&#8216;Last 14 Days&#8217;</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelection]</span><br />
<span style="color: silver;">,</span><span style="color: black;">5</span> <span style="color: blue;">AS</span> <span style="color: maroon;">[DateIntervalSelectionOrder]</span><br />
<span style="color: blue;">FROM</span> <span style="color: maroon;">sys</span><span style="color: silver;">.</span><span style="color: maroon;">all_objects</span> <span style="color: maroon;">a</span></p>
<p>&nbsp;</p>
<p>What this produces is a DateInterval table with three columns &#8211; DateIntervalSelection, DateIntervalSelectionOrder and Dates . A sample preview is shown below for MTD, QTD, and YTD</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2544" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/table1.png" alt="" width="396" height="553" /></p>
<p>A couple of things to note here: Say for YTD you will notice that for every day in 2021 there is a corresponding day in 2020. This is the case for QTD and MTD as well. This is necessary as will be plotting YTD and YTD Previous Year in the same chart and we need to have dates for both the calculation items in the DateInteval table.This will make more sense when we define these calculation items below</p>
<p>Add three more calculation items to the TimeIntelligence calculation group YTD PY, QTD PY, MTD PY. These are the items for the &#8220;To Date&#8221; values for the previous year. We also need to make changes to YTD, QTD, and MTD</p>
<p>MTD PY:<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;MTD&#8221;</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">TOTALYTD</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATEADD</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCalendar[DateID], <span class="Number" style="color: #ee7f18;">-12</span>, <span class="Keyword" style="color: #035aca;">MONTH</span> <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>MTD:<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">_CurrentYear</span> = [0_CurrentYear]<br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;MTD&#8221;</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DATESMTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span>&#8216;DimCalendar'[CalendarYear] = <span class="Variable" style="color: #49b0af;">_CurrentYear</span><br />
<span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>QTD PY:<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;QTD&#8221;</span>,<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">TOTALYTD</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATEADD</span><span class="Parenthesis" style="color: #808080;"> (</span> DimCalendar[DateID], <span class="Number" style="color: #ee7f18;">-4</span>, <span class="Keyword" style="color: #035aca;">QUARTER</span> <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>QTD:<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">_CurrentYear</span> = [0_CurrentYear]<br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;QTD&#8221;</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DATESQTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span>&#8216;DimCalendar'[CalendarYear] = <span class="Variable" style="color: #49b0af;">_CurrentYear</span><br />
<span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>YTD PY:<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">_CurrentYear</span> = [0_CurrentYear]<br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;YTD&#8221;</span><br />
<span class="indent8">        </span><span class="indent4">    </span>|| <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">TOTALYTD</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>, <span class="Keyword" style="color: #035aca;">DATEADD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID], <span class="Number" style="color: #ee7f18;">-1</span>, <span class="Keyword" style="color: #035aca;">YEAR</span> <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span>&#8216;DimCalendar'[CalendarYear] = <span class="Variable" style="color: #49b0af;">_CurrentYear</span><br />
<span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>YTD:<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">_CurrentYear</span> = [0_CurrentYear]<br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="StringLiteral" style="color: #d93124;">&#8220;YTD&#8221;</span><br />
<span class="indent8">        </span><span class="indent4">    </span>|| <span class="Keyword" style="color: #035aca;">NOT</span><span class="Parenthesis" style="color: #808080;"> (</span> <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDMEASURE</span><span class="Parenthesis" style="color: #808080;"> (</span><span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">DATESYTD</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;DimCalendar'[DateID] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span>&#8216;DimCalendar'[CalendarYear] = <span class="Variable" style="color: #49b0af;">_CurrentYear</span><br />
<span class="indent8">        </span><span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>We can now start to visualise the data. The following video will give the details</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2538-2" width="1080" height="675" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_154201.mp4?_=2" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_154201.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_154201.mp4</a></video></div>
<p>&nbsp;</p>
<p>The dashboard is already looking good. Now what if we wanted to visualise YTD, MTD, QTD etc for other metrics ? This is easier to do. We define another calculation group called KPI and define these calculation items as</p>
<p>Sales: [Total Sales]</p>
<p>Quantity: [Total Order Quantity]</p>
<p>Sales : [Total Sales]</p>
<p>We save the model and place another slicer on the report and drag the KPI column into that slicer. The report now looks like this</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2538-3" width="1080" height="675" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_155456.mp4?_=3" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_155456.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_155456.mp4</a></video></div>
<p>&nbsp;</p>
<p>You will notice that though the report works fine, the titles are not updated when you change the metrics. This can be overcome by defining a disconnected table instead of using a calculated group. We define a disconnected table as below and call it MetricTable</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2558" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/Screenshot-2021-03-01-092241.png" alt="" width="160" height="91" /></p>
<p>We also need to update the metric slicer with values from the MetricName column from this table. We then define a measure which calls the appropriate measure when we select a metric name from the slicer</p>
<p>Metric =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">a</span> =<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SWITCH</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Variable" style="color: #49b0af;">a</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;Sales&#8221;</span>, [Total Sales],<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;Quantity&#8221;</span>, [Total Order Quantity],<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;Tax&#8221;</span>, [Total Tax Amount]<br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>We also define three more measures for the titles for the three charts.</p>
<p>Title Daily Values =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">a</span> =<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SWITCH</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Variable" style="color: #49b0af;">a</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;YTD&#8221;</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8220;This Year&#8221;</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;QTD&#8221;</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8220;This Quarter&#8221;</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;MTD&#8221;</span>,<br />
<span class="indent8">        </span><span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8220;This Month&#8221;</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span><br />
<span class="indent8">        </span><span class="indent4">    </span>&amp; <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Title Date Interval =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">a</span> =<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Variable" style="color: #49b0af;">a</span> <span class="Keyword" style="color: #035aca;">IN</span> { <span class="StringLiteral" style="color: #d93124;">&#8220;YTD&#8221;</span>, <span class="StringLiteral" style="color: #d93124;">&#8220;QTD&#8221;</span>, <span class="StringLiteral" style="color: #d93124;">&#8220;MTD&#8221;</span> },<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span><br />
<span class="indent8">        </span><span class="indent4">    </span>&amp; <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;&#8221;</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Title Top Product =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">a</span> =<br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SWITCH</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent8">        </span><span class="Variable" style="color: #49b0af;">a</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;YTD&#8221;</span>, <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; This Year: TOP 20 Products&#8221;</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;QTD&#8221;</span>, <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; This Quarter: TOP 20 Products&#8221;</span>,<br />
<span class="indent8">        </span><span class="StringLiteral" style="color: #d93124;">&#8220;MTD&#8221;</span>, <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; This Month: TOP 20 Products&#8221;</span>,<br />
<span class="indent8">        </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> MetricTable[MetricName] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8221; &#8211; &#8220;</span><br />
<span class="indent8">        </span><span class="indent4">    </span>&amp; <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> DateInterval[DateIntervalSelection] <span class="Parenthesis" style="color: #808080;">)</span> &amp; <span class="StringLiteral" style="color: #d93124;">&#8220;: TOP 20 Products&#8221;</span><br />
<span class="indent4">    </span><span class="Parenthesis" style="color: #808080;">)</span></p>
<p>&nbsp;</p>
<p>Finally we conditionally format the titles of the charts and update the Values field in the chart to the measure [Metric] to produce the following report</p>
<p>&nbsp;</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2538-4" width="1080" height="675" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210301_093859.mp4?_=4" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210301_093859.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210301_093859.mp4</a></video></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>You can download the PBIX file by clicking the link below</p>
<p><a href="https://drive.google.com/u/0/uc?id=1A1LF3gHOOK6Vd1bpUNkQIm-cyRa9nGcy&amp;export=download">Download Report</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/executive-dashboard-using-calculation-groups-date-interval-table-and-disconnected-tables/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210225_163809.mp4" length="427769" type="video/mp4" />
<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_154201.mp4" length="1575289" type="video/mp4" />
<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210226_155456.mp4" length="1003934" type="video/mp4" />
<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/02/20210301_093859.mp4" length="1046363" type="video/mp4" />

			</item>
		<item>
		<title>Changing bookmark button behaviour using disconnected tables and DAX</title>
		<link>https://capstoneanalytics.com.au/changing-bookmark-button-behaviour-using-disconnected-tables-and-dax/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-bookmark-button-behaviour-using-disconnected-tables-and-dax</link>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Sat, 09 Jan 2021 08:22:45 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Bookmarks]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Disconnected tables]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2449</guid>

					<description><![CDATA[Bookmarks are a great way to story tell in Power BI as they can be used to save pre configured states in a report. However they have drawbacks in that you have to create two versions of a button for each bookmark and show/hide one of them depending on the bookmark state. This becomes cumbersome [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Bookmarks are a great way to story tell in Power BI as they can be used to save pre configured states in a report. However they have drawbacks in that you have to create two versions of a button for each bookmark and show/hide one of them depending on the bookmark state. This becomes cumbersome to manage when you have a lot of bookmarks across multiple pages in a report.</p>
<p>An alternate is to use disconnected tables and DAX to drive bookmark button behaviour. The advantage of this option is that you only have one bookmark button for each  bookmark and you have to configure its behaviour using DAX. You set up the DAX formulas just once and you can use the same set of bookmarks for other pages in the report.</p>
<p>To get started we open up a Power BI model and create a disconnected table called BookmarkFlag and create a new column called Value with five rows with values &#8211; 1, 2, 3, 4, 5</p>
<p>Now we need to create a few DAX measures to store the HEX properties of the colours we are going to use in the bookmark buttons. We will be using different colours for text and fill for the button text and fill. Hence we define four DAX measures as follows:</p>
<p>DefaultHoverTextColour = <span class="StringLiteral" style="color: #d93124;">&#8220;#B3B3B3&#8221;</span></p>
<p>DefaultTextColour = <span class="StringLiteral" style="color: #d93124;">&#8220;#E6E6E6&#8221;</span></p>
<p>SelectedColour = <span class="StringLiteral" style="color: #d93124;">&#8220;#FFFFFF&#8221;</span></p>
<p>SelectedFillColour = <span class="StringLiteral" style="color: #d93124;">&#8220;#FF6E15&#8221;</span></p>
<p>Next we go ahead and create a simple chart as below which shows the sales amount for the four hierarchies &#8211; SalesTerritoryGroup, SalesTerritoryCountry, SalesTerritoryRegion, Size</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2450" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture.png" alt="" width="1079" height="521" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture.png 1079w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-980x473.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-480x232.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1079px, 100vw" /></p>
<p>Next we create four bookmark buttons so that each one of them when clicked shows the sales for each hierarchy. They are also named appropriately as below<img loading="lazy" decoding="async" class="alignnone size-full wp-image-2452" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture1-1.png" alt="" width="1154" height="269" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture1-1.png 1154w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture1-1-980x228.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture1-1-480x112.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1154px, 100vw" /></p>
<p>Next we need to define a series of DAX measures to drive the behaviour of the bookmark buttons. We define three measures for the first button as follows</p>
<p>Button 1 Fill Colour =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;BookmarkFlags'[Value] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="Number" style="color: #ee7f18;">1</span>,<br />
<span class="indent4">    </span>[SelectedFillColour],<br />
<span class="indent4">    </span>[SelectedColour]<br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Button 1 Hover Text Colour =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;BookmarkFlags'[Value] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="Number" style="color: #ee7f18;">1</span>,<br />
<span class="indent4">    </span>[SelectedColour],<br />
<span class="indent4">    </span>[DefaultHoverTextColour]<br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Button 1 Text Colour =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;BookmarkFlags'[Value] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="Number" style="color: #ee7f18;">1</span>,<br />
<span class="indent4">    </span>[SelectedColour],<br />
<span class="indent4">    </span>[DefaultTextColour]<br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Use the above template to create 9 more measures, 3 for each button and replacing <span class="Keyword" style="color: #035aca;">SELECTEDVALUE</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;BookmarkFlags'[Value] <span class="Parenthesis" style="color: #808080;">)</span> = <span class="Number" style="color: #ee7f18;">1 </span> with 2, 3,4 respectively for each button. With 12 measures created we are now ready to apply them to the buttons</p>
<p>Select the first button and apply conditional formatting to the button text colour for the three states &#8211; default, on hover, on press. Also apply conditional formatting on the fill colour. The following video shows which measure to use and how to do it.</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2449-5" width="1080" height="608" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_174044.mp4?_=5" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_174044.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_174044.mp4</a></video></div>
<p>Use the same process and apply conditional formatting for Buttons 2, 3, 4 by using the appropriate measures. The four bookmark buttons should look like the below with the default text applied.<img loading="lazy" decoding="async" class="alignnone size-full wp-image-2453" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-1.png" alt="" width="991" height="150" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-1.png 991w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-1-980x148.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2021/01/Capture-1-480x73.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 991px, 100vw" /></p>
<p>Open the bookmark pane and create four bookmarks and call them Bookmark 1, Bookmark 2, Bookmark 3, Bookmark 4.The final part involves updating the bookmarks by changing the value of the column Value from the BookmarkFlag table for each bookmark and updating the bar chart for each bookmark. We do this as below.</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2449-6" width="1080" height="608" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181607.mp4?_=6" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181607.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181607.mp4</a></video></div>
<p>.</p>
<p>The final step is to assign each bookmark button its respective bookmark and then start browsing !</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2449-7" width="1080" height="608" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181937.mp4?_=7" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181937.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181937.mp4</a></video></div>
<p><a href="https://drive.google.com/u/0/uc?id=1jRm6W7Xk2pTlkG4Q_AfaYFrfAOHQ8AZR&amp;export=download">Download report</a></p>
]]></content:encoded>
					
		
		<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_174044.mp4" length="2012272" type="video/mp4" />
<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181607.mp4" length="3663651" type="video/mp4" />
<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2021/01/20210109_181937.mp4" length="1686865" type="video/mp4" />

			</item>
		<item>
		<title>Using DAX to prevent users from entering the detailed pages from a landing page until every slicer is selected</title>
		<link>https://capstoneanalytics.com.au/using-dax-to-prevent-users-from-entering-the-detailed-pages-from-a-landing-page-until-every-slicer-is-selected/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-dax-to-prevent-users-from-entering-the-detailed-pages-from-a-landing-page-until-every-slicer-is-selected</link>
					<comments>https://capstoneanalytics.com.au/using-dax-to-prevent-users-from-entering-the-detailed-pages-from-a-landing-page-until-every-slicer-is-selected/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Sat, 06 Jun 2020 04:54:46 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Conditional Formatting]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Page Destination]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2260</guid>

					<description><![CDATA[Suppose you have a landing page and you have a bunch of slicers on the page and you want the users to select at least one option on the slicers before they can enter the next page. It wasn&#8217;t possible with bookmarks before as you couldnt switch bookmarks using conditional formatting but you can do [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Suppose you have a landing page and you have a bunch of slicers on the page and you want the users to select at least one option on the slicers before they can enter the next page. It wasn&#8217;t possible with bookmarks before as you couldnt switch bookmarks using conditional formatting but you can do this using conditional formatting and the destination option.</p>
<p>We will use the Adventureworks database for this post. Create a page and call it &#8216;Summary Page&#8217;. This is where you want the users to enter from the landing page. I have created a few card visuals and line charts in the Summary Page for this exercise as follows</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2261" src="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Summary-page.png" alt="" width="1270" height="598" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Summary-page.png 1270w, https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Summary-page-980x461.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Summary-page-480x226.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1270px, 100vw" /></p>
<p>Next create a new page and call it &#8216;Landing Page&#8217;. Create three slicers on the page for Class, Colour, and SalesTerritoryCountry. Create a new blank button and apply some formatting to look like this</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2262" src="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/landing-page.png" alt="" width="1067" height="399" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/landing-page.png 1067w, https://capstoneanalytics.com.au/wp-content/uploads/2020/06/landing-page-980x366.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2020/06/landing-page-480x179.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1067px, 100vw" /></p>
<p>We now need to define a measure which will see if all of the three slicers are filtered and then give the name of the pages.</p>
<p>Destination Page =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Class] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Color] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent8">        </span>&amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Territories'[SalesTerritoryCountry] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;Summary Page&#8221;</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;Landing Page&#8221;</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Remember to give the exact name of the page in the measure.</p>
<p>We will also define two more measures for the tooltips and button text</p>
<p>Destination Page Tooltip =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Class] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Color] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent8">        </span>&amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Territories'[SalesTerritoryCountry] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;Press Enter to go to Summary page&#8221;</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;Please select at least one option in all three slicers &#8220;</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Button Text =<br />
<span class="Keyword" style="color: #035aca;">IF</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="indent4">    </span><span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Class] <span class="Parenthesis" style="color: #808080;">)</span> &amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Product'[Color] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="indent8">        </span>&amp;&amp; <span class="Keyword" style="color: #035aca;">ISFILTERED</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Dim Territories'[SalesTerritoryCountry] <span class="Parenthesis" style="color: #808080;">)</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;ENTER&#8221;</span>,<br />
<span class="indent4">    </span><span class="StringLiteral" style="color: #d93124;">&#8220;STOP&#8221;</span><br />
<span class="Parenthesis" style="color: #808080;">)</span></p>
<p>Now its the time to apply these measures to the button we created. With the button expand Action and in the Type option select Page navigation. Under Destination click the conditional formatting option (fx) and under &#8216;Format by&#8217; choose &#8216;Field Value&#8217; and select Destination Page as the measure under &#8216;Based on field&#8217; and press OK. Similarly for tooltips follow the same steps and choose Destination Page Tooltip as the measure and press OK. Now expand the Button Text option right at the top and leave ENTER as the button text for the Default state. Select &#8216;On hover&#8217; from the dropdown and click the conditional formatting option (fx) and  under &#8216;Format by&#8217; choose &#8216;Field Value&#8217; and select Button Text as the measure under &#8216;Based on field&#8217; and press OK. Select &#8216;On press&#8217; from the dropdown and follow the previous step.</p>
<p>Now you are ready to interact with the button on the landing page. When all three slicers are not filtered notice how the button text changes and also the tooltip and you wont be able to go to the next page. Only when all three slicers are selected can you go to the next page.</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2260-8" width="1080" height="570" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Landing-page.mp4?_=8" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Landing-page.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Landing-page.mp4</a></video></div>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/using-dax-to-prevent-users-from-entering-the-detailed-pages-from-a-landing-page-until-every-slicer-is-selected/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2020/06/Landing-page.mp4" length="384978" type="video/mp4" />

			</item>
		<item>
		<title>Data storytelling by using the Page Navigation button</title>
		<link>https://capstoneanalytics.com.au/data-storytelling-by-using-the-page-navigation-button/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=data-storytelling-by-using-the-page-navigation-button</link>
					<comments>https://capstoneanalytics.com.au/data-storytelling-by-using-the-page-navigation-button/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Fri, 27 Mar 2020 05:55:12 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[Bookmarks]]></category>
		<category><![CDATA[Data Storytelling]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Page Navigation]]></category>
		<category><![CDATA[Rolling Average]]></category>
		<category><![CDATA[Trend]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2167</guid>

					<description><![CDATA[Data storytelling is increasingly being seen as essential to modern data analysis It is no longer enough to just develop a data model and produce visuals and let the audience take it from there. Reports need to be developed with the end user in mind while taking them on a journey so that the users [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Data storytelling is increasingly being seen as essential to modern data analysis</p>
<p>It is no longer enough to just develop a data model and produce visuals and let the audience take it from there.</p>
<p>Reports need to be developed with the end user in mind while taking them on a journey so that the users have a better understanding of the data. This can be achieved by data storytelling techniques like strategic colouring, drill through, bookmarks and also providing enough visual cues so that the audience can drive the reports without much training.</p>
<p>In Power BI you can incorporate features such as bookmarks and drill through for story telling. The new Page Navigation option is even better as now you can quickly develop reports and let the audience drive them without much effort,</p>
<p>Watch the video for a demo on how it can be achieved. I have used two time series data and plotted it in a line chart along with average, max, min, rolling average and trend lines. That&#8217;s a lot of information on a line chart. But with effective storytelling you can introduce these elements one by one so that the end users have time to process all the information.</p>
<p>&nbsp;</p>
<div style="width: 1080px;" class="wp-video"><video class="wp-video-shortcode" id="video-2167-9" width="1080" height="573" preload="metadata" controls="controls"><source type="video/mp4" src="https://capstoneanalytics.com.au/wp-content/uploads/2020/03/Brisbane-Temperature.mp4?_=9" /><a href="https://capstoneanalytics.com.au/wp-content/uploads/2020/03/Brisbane-Temperature.mp4">https://capstoneanalytics.com.au/wp-content/uploads/2020/03/Brisbane-Temperature.mp4</a></video></div>
<p>&nbsp;</p>
<p>Link to interactive report: <a href="https://app.powerbi.com/view?r=eyJrIjoiMmE0MjM3NjEtN2Q2MS00MGUwLTg3ODMtZjI1ZGI1Y2E2OTdjIiwidCI6IjZjZDI2M2IwLTQxNmItNGY5MC04ZDRmLTJmNmE1YjU2OGM1ZSJ9">Data storytelling by page navigation in Power BI</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/data-storytelling-by-using-the-page-navigation-button/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="https://capstoneanalytics.com.au/wp-content/uploads/2020/03/Brisbane-Temperature.mp4" length="2112524" type="video/mp4" />

			</item>
	</channel>
</rss>
