<?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>Capstone Analytics</title>
	<atom:link href="https://capstoneanalytics.com.au/feed/" rel="self" type="application/rss+xml" />
	<link>https://capstoneanalytics.com.au</link>
	<description>Analytics Simplified</description>
	<lastBuildDate>Fri, 21 Feb 2025 00:05:28 +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>Importing comments from Databricks Unity Catalog to Power BI</title>
		<link>https://capstoneanalytics.com.au/importing-comments-from-databricks-unity-catalog-to-power-bi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=importing-comments-from-databricks-unity-catalog-to-power-bi</link>
					<comments>https://capstoneanalytics.com.au/importing-comments-from-databricks-unity-catalog-to-power-bi/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Fri, 21 Feb 2025 00:05:28 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[databricks]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2955</guid>

					<description><![CDATA[If you are still copy-pasting comments from Databricks Unity Catalog into Power BI you need to stop scrolling and read this post. I have been working with Databricks lately and have been impressed by how modern the interface is, everything is accessible via a web browser (as opposed to using SSMS for Azure). You have [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you are still copy-pasting comments from Databricks Unity Catalog into Power BI you need to stop scrolling and read this post.</p>
<p>I have been working with Databricks lately and have been impressed by how modern the interface is, everything is accessible via a web browser (as opposed to using SSMS for Azure). You have data lineage, ability to share queries, and most importantly there is a catalog of every table and views where you get an overview of the artifacts, sample data, history etc.</p>
<p>One thing that got my attention was the ability to add comments to table/view columns in the catalog. Now if you are importing these views into your Power BI semantic model, you would want to import the column comments into the descriptions of the Power BI columns. There is no native way to achieve this in Power BI. Here comes the &#8216;information_schema&#8217; to the rescue.</p>
<p>In the &#8216;information_schema&#8217; there is metadata listed for all the tables and views in the catalog. The comments on each column is also listed. So how do we get this inside Power BI.</p>
<p>Let&#8217;s explore 3 options</p>
<p>1. Copy-paste. It&#8217;s 2025 AD, not 2025 BC, so this is a BIG NO.</p>
<p>2. Run a SQL query on the &#8216;information_schema&#8217; and export the relevant fields (view name, column name, comments) into a csv and use Tabular Editor to import the comments into the description property for each column.</p>
<p>Not a bad idea, except that it is still a manual process to run the query and save it as a csv. You might be able to automate the export (havent tried it though), but you still have to deal with a csv file which you have to manage.</p>
<p>3. Use a C# script in Tabular Editor to import the comments into the description property of the columns in your semantic model. This can be part of the build process. Now we are talking. So how do we do this.</p>
<p>Import the relevant fields from the &#8216;information_schema&#8217; into your semantic model as a separate table. You will also need a mapping table to map the view name from Databricks to the table name in Power BI.</p>
<p>Run the script below and you are done ! That&#8217;s it ! With a bit of once off set up work in your semantic model you can now import comments from views in Databricks into your enterprise models !</p>
<p><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2956" src="https://capstoneanalytics.com.au/wp-content/uploads/2025/02/Picture1.png" alt="" width="4400" height="2415" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2025/02/Picture1.png 4400w, https://capstoneanalytics.com.au/wp-content/uploads/2025/02/Picture1-1280x703.png 1280w, https://capstoneanalytics.com.au/wp-content/uploads/2025/02/Picture1-980x538.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2025/02/Picture1-480x263.png 480w" sizes="(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) 4400px, 100vw" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/importing-comments-from-databricks-unity-catalog-to-power-bi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Musings from developing and deploying enterprise grade semantic models &#8211; Part 3: Technical learnings</title>
		<link>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part3-technical-learnings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=musings-from-developing-and-deploying-enterprise-grade-semantic-models-part3-technical-learnings</link>
					<comments>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part3-technical-learnings/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Mon, 30 Jan 2023 10:43:33 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Enterprise Semantic Model]]></category>
		<category><![CDATA[Semantic Layer]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2888</guid>

					<description><![CDATA[In Part 1 of this series we introduced the concept of enterprise grade semantic models and in Part 2 we discussed some general learnings from developing and deploying enterprise grade semantic models. In Part 3 we will discuss the technical learnings. You won&#8217;t find a treatise on how to do each thing in detail but [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://capstoneanalytics.com.au/learnings-from-developing-enterprise-grade-semantic-models/">Part 1</a> of this series we introduced the concept of enterprise grade semantic models and in <a href="https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings/">Part 2</a> we discussed some general learnings from developing and deploying enterprise grade semantic models. In Part 3 we will discuss the technical learnings. You won&#8217;t find a treatise on how to do each thing in detail but hopefully there is enough content in here to start thinking about applying some of these learnings in your project.</p>
<p>The learnings are divided into 4 sections: IMPORT, MODEL, REFRESH, SUPPORT. These correspond to roughly the four main tasks of a semantic modeller.</p>
<h3>IMPORT</h3>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Apply transformations as left as possible</h5>
<p>All reusable logic needs to be shifted as left as possible and as close to the source as practical. This is to ensure that the databases do all the heavy lifting (extract, transform and load) and your semantic model becomes a layer to aggregate the metrics via measures rather than an ETL layer. This diagram from Part 1 shows where the various transformations and measures are defined</p>
<p><img decoding="async" class="alignnone size-full wp-image-2943" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/10/Picture1.png" alt="" width="3922" height="1468" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/10/Picture1.png 3922w, https://capstoneanalytics.com.au/wp-content/uploads/2022/10/Picture1-1280x479.png 1280w, https://capstoneanalytics.com.au/wp-content/uploads/2022/10/Picture1-980x367.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/10/Picture1-480x180.png 480w" sizes="(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) 3922px, 100vw" /></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Star schema model is preferred</h5>
<p>A star schema is the best technique for faster reports and lesser memory consumption. An enterprise model may have multiple star schemas in the same model, with fact tables linked to conformed dimensions. This is the first step in getting the semantic model right. If it is not star schema, performance will suffer.</p>
<p><img decoding="async" class="" src="https://learn.microsoft.com/en-us/power-bi/guidance/media/star-schema/star-schema-example2.png" alt="Understand star schema and the importance for Power BI - Power BI | Microsoft Learn" width="853" height="602" /><br />
<em>Image source</em>: <a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Flearn.microsoft.com%2Fen-us%2Fpower-bi%2Fguidance%2Fstar-schema&amp;psig=AOvVaw0P2Kug0_YtWEU5ifQo12gp&amp;ust=1675072384929000&amp;source=images&amp;cd=vfe&amp;ved=0CA8QjRxqFwoTCPi02oXB7PwCFQAAAAAdAAAAABAE">MS Learn</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Use views instead of tables</h5>
<p>Use views to import data into your Power BI model. Using views has three advantages<br />
1. Tables generally do not contain business friendly names. They might have a name such as MemberAccountBalance_Total which is not user friendly. You can write this in a view as Member Account Balance.<br />
2. You can remove/add columns in views. Tables often contain columns such as Record_From_Date, Record_To_Date etc which are required for testing purposes but are not required in the semantic model. So you can remove such columns in the views. You can also add new columns in the views. These are commonly report level logic which are specific to certain reports. So if you want to bin your data, you can write that logic in the views.<br />
3. You can join multiple tables in views. Sometimes the views are not straight forward and you might want to join multiple tables to form one view to meet the reporting requirements.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Simplify views &#8211; resulting in simpler DAX</h5>
<p>Simplify views as much as possible so that the DAX becomes simpler, and the queries perform faster. The goal of the semantic model is not to show off your DAX, in fact it is the exact opposite. The semantic model should only contain simple aggregations like SUM, DISTINCTCOUNT, AVERAGE and/or simple filters in CALCULATE. If you are traversing multiple tables with DAX then it&#8217;s too complex. Move the logic back to the tables/views so that the DAX is simplified.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Do not import all data into desktop</h5>
<p>This is the key to making your model lighter in desktop and faster to publish. A model I&#8217;m currently working on is ~12GB in Power BI service (memory) while it only occupies 4MB of disk space on my laptop. How is it even possible? The trick is to only import a fraction of the data into your desktop model. You can either import only 1000 rows for each table and/or use a &#8216;Start Date&#8217; parameter to only import from a certain date onwards. Use parameters to achieve this as explained below.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Parameterize everything</h5>
<p>Use parameters in Power Query. Parameters can be used to store server name, database name, schema name, Start Date. A typical parameter can look like this:</p>
<p><img decoding="async" src="https://mail.google.com/mail/u/0?ui=2&amp;ik=bcae2b5ab2&amp;attid=0.1&amp;permmsgid=msg-a:r1347536324243995491&amp;th=1860074a037328c7&amp;view=fimg&amp;fur=ip&amp;sz=s0-l75-ft&amp;attbid=ANGjdJ-nhtobk4XwObKHVXD5cuCWaHoPTUC77KD2-lKG4FUIXBdAv0e7ImGDO6Px2JuVo0KAcGc6AelcCQTFioy0AzV3yuFqwiDLV_f7XjfjwfpSgYUJ-8J3mQrcHJg&amp;disp=emb&amp;realattid=ii_ldi6bmem0" alt="image.png" /></p>
<p>The advantage of using parameters are twofold:<br />
1. You can have different names for servers, databases in different environments. This is crucial as you would publish your model to a UAT/SIT environment first and then push it to production. And normally non prod environments have a different set of servers and databases<br />
2. You can quickly change names of servers, databases, schemas if they are renamed at the source. Without parameters you would have to manually go to each query and change it, which would be time consuming.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Utilise query folding in power query</h5>
<p>One of the core principles of an enterprise model is that all columns have to be defined in the views and not in Power BI. However, you can certainly remove some columns in Power Query which you may not want to import into your model. An example would be fact table primary keys. These keys are normally created for testing purposes but don&#8217;t serve a modelling or reporting purpose. So, you can remove them in Power Query. Another step you might apply in power query is a filtering step to limit the rows being imported. Ensure that these two steps still utilise query folding (from my experience they should)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<h3>MODEL</h3>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Use desktop for DEV</h5>
<p>Since you are only bringing in a fraction of the data into the desktop model, it cannot be used to test the data. Use it as a development (DEV) workspace where you apply all column and DAX formatting, table naming, column ordering etc. Since its a lighter model you can easily push the changes to UAT/SIT workspace with the use of external tools (see Use External Tools section).</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Give descriptions for tables and fields</h5>
<p>It&#8217;s not just important to import all the data and write good DAX it is also important to provide descriptions to all entities used by the business users in the model (tables, columns, measures, hierarchy) so that they exactly know what those entities are and how they can be used.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Follow the eleven rules of DAX management</h5>
<p>DAX is the window of the semantic model to the outside world. It is via the DAX measures that users interact with the model. Hence the measures need to be appropriately named, faster to query, and proper formatting applied. Go through this <a href="https://capstoneanalytics.com.au/the-eleven-rules-of-dax-management/">article</a> to apply all the eleven rules of DAX management before pushing the measures to production.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Use external tools</h5>
<p>The use of external tools greatly increases productivity and agility. There are three main tools which are of importance, and they should be in the arsenal of every semantic modeler. They are all free to use and if you do not have them, get your IT department to install them for you.</p>
<p><a href="https://docs.tabulareditor.com/index.html">Tabular Editor</a></p>
<p>Tabular Editor is a tool that lets you easily manipulate and manage measures, calculated columns, display folders, perspectives and translations in Analysis Services Tabular and Power BI Models. You can also automate a lot of the modelling process by writing C# scripts that interacts with the Tabular Model and edits the model. There are a lot of custom C# scripts freely available to get your started. Once you get to know the objects you can manipulate in the Tabular Object Model, you can easily write scripts that performs formatting, column ordering, relationship creation etc. Modelling using Tabular Editor is a breeze and once you start using it you will never go back to using the clunky desktop GUI for your work.</p>
<p><a href="https://daxstudio.org/">DAX Studio</a></p>
<p>This is the ultimate tool for working with DAX queries. If you are writing lots of DAX, be it in the semantic model or report level measures you can test your queries for speeds, server timings, query plan etc. You can also use the DMV (Dynamic Management Views) to query the TOM model and get important insights like table size, number of rows, measure expressions etc.</p>
<p><a href="http://alm-toolkit.com/">ALM Toolkit</a></p>
<p>This is a great toolkit to manage and publish your datasets to different workspaces. You can compare two datasets and see what is different and push the changes you want to the workspace of your choice. By using this toolkit you are only pushing the metadata changes to a workspace and not the entire dataset. So if you have added 10 new measures into your desktop model, instead of publishing it the manual way using Power BI desktop and updating the model in service and running a refresh on it again, you only update the measures using this toolkit, without a need to refresh the entire model. A must have external tool for agile delivery.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Apply incremental refresh where possible</h5>
<p>Incremental refresh is a great way to reduce the memory footprint of your models while refreshing. When you apply incremental refresh policy on a fact table in your model you are locking in the past data and only incrementally refreshing the most recent data. Say you have a large fact table in your dataset with 200 million rows and five years&#8217; worth of data and you want to reduce the number of rows to be refreshed every day, you could apply an incremental refresh policy and lock in the first 4 years of data and only refresh the current year. So, every day the fact table only gets data for the current year which would be much less than 200 million which means the model consumes less memory during refresh and you stay well within your memory limit (in case of Power BI Premium subscription).</p>
<p>However, be mindful of the fact that if a table reload is required at the source, then you would need to disable incremental refresh in the model and bring in all the data once again. Be very careful of applying incremental refresh on a table in the model. Only do so when you are 100% sure that no table reloads will occur in the future.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<h3>REFRESH</h3>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Use pipelines in service</h5>
<p>Use deployment pipelines in Power BI service to push your models fom UAT to PROD. Deployment pipelines enable semantic modelers to manage the testing and publishing of their semantic models. You can also publish reports, paginated reports, dashboards, as well as dataflows. You can also automate it by using the <a href="https://learn.microsoft.com/en-us/power-bi/create-reports/deployment-pipelines-automation#use-the-power-bi-automation-tools-extension">Power BI Automation Tools Extension</a> in DevOps which is an effcient way of deploying models especially if there are multiple modes.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Automate refresh</h5>
<p>Automatic refresh of semantic models doesnt mean setting up a refresh schedule for the models. This will not work as if the underlying tables are being reloaded, say each night in the data warehouse the exact time of when the reloads are complete cannot be determined. Hence setting up a scheduled refresh for the semantic models means that the model will start refreshing before the reloads have finished. This results in time out issues apart from not refreshing the latest data.</p>
<p>In order to avoid such a scenario use the <a href="https://learn.microsoft.com/en-us/power-bi/connect-data/asynchronous-refresh">Power BI REST API</a> to refresh the models after the reload is complete. Using this APT you can also fine tune the refresh by specifying the Max Parallelism values, tables and partitions to refresh.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Monitor refresh</h5>
<p>Use the <a href="https://learn.microsoft.com/en-us/power-bi/enterprise/service-premium-gen2-metrics-app">Gen2 Metrics App</a> to monitor the Power BI Gen2 premium capacities. Among the features of this dashboard is the ability to monitor the refresh times, peak memory consumption, CPU usage and number of users utilising your semantic models.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>SUPPORT</h3>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Use source control</h5>
<p>Source control is a tricky subject in the Power BI world as there is no built in source control within Power BI. You would need to use a combination of Sharepoint/DevOps to manage your pbix/template files. A good place to start on an automated way to keep track of pbix files is here</p>
<p><a href="https://mutt0-ds.github.io/posts/2022/11/turbulent-journey-power-bi-source-control/">A turbulent journey through Power BI source control &#8211; Mutt0-ds Notes</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Document the model</h5>
<p>It is important to document the model in production so that everyone from Managers to developers know what entities are available in the model. You can do this manually via Sharepoint/Confluence but it becomes cumbersome to maintain and error prone. An automated data glossary dashboard which extracts the metadata from your models in production is a much better scenario. This glossary gives you details on<br />
&#8211; M expressions of each query<br />
&#8211; Number of tables and columns in the model<br />
&#8211; Number of measures and their expressions<br />
&#8211; BUS matrix<br />
&#8211; Number of rows in the tables<br />
&#8211; Size of tables and columns in the model<br />
&#8211; Lineage between data warehouse tables/view to measures</p>
<p>Talk to us if you need help in implementing such a data glossary for your models.</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Optimize the model</h5>
<p>Models in production should always be optimised to ensure they consume less memory and refresh and query faster. Memory is at a premium in Power BI (forgive the pun) so you should always strive to make sure the models only use the bare minimum necessary to meet the reporting requirements. Here are some steps to perform to make sure models refresh faster and consume less memory<br />
&#8211; Remove unnecessary columns from tables, especially fact table primary key columns<br />
&#8211; Filter rows which are not required for reporting. If there is only a reporting requirement for the last five years, do not include data from 2010 onwards<br />
&#8211; Decrease precision of decimal fields to 2 decimal points<br />
&#8211; Set MDX as false to non attribute columns (PK, DK, Record_effective)<br />
&#8211; Set right encoding for columns &#8211; dimension tables should have hash encoding and decimal fields benefit from value<br />
&#8211; Custom partition on tables<br />
&#8211; Reducing cardinality<br />
&#8211; Do not use calculated columns<br />
&#8211; Use aggregated tables if detailed grain is not required for reporting</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Automate semantic model testing</h5>
<p>How do you ensure that the measures you have written are correct? How do you know that the business can trust the numbers coming from the measures ? One way to do that is to test your semantic model against the source of the measures which in most cases are views. You can use the <a href="https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries">Execute Queries API</a> to query your models in production, extract the measure results and compare them against an equivalent SQL statement from the views. If you have a tester they can set up a testing framework in ADF and it can be automated to make sure that the measures are always giving the correct results.</li>
</ul>
</li>
</ul>
<p>So there it is, the end of this series on my musings from developing and deploying enterprise grade semantic models. As a parting note, developing enterprise grade semantic models is an exciting role to work in as you get to collaborate with a wide variety of stakeholders while having ultimate control over the semantic model. Treat it like a product and make sure you listen deeply to the users before adding any new features. Finally, your job as a semantic modeler is to make it easier for the end users to create reports. Provide as much details as possible on how to use it and evangelise it to everyone you meet in the organisation. All the best !</li>
</ul>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part3-technical-learnings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Musings from developing and deploying enterprise grade semantic models &#8211; Part 2: General learnings</title>
		<link>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings</link>
					<comments>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Mon, 31 Oct 2022 05:43:11 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Enterprise Semantic Model]]></category>
		<category><![CDATA[Semantic Layer]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2873</guid>

					<description><![CDATA[In Part 1 of this series, I gave a brief introduction to the concept of semantic models and why they should be designed. In this article I discuss the general learnings from developing and deploying semantic models If you are doing it all by yourself, it is not enterprise grade As discussed in Part 1 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In <a href="https://capstoneanalytics.com.au/learnings-from-developing-enterprise-grade-semantic-models/">Part 1</a> of this series, I gave a brief introduction to the concept of semantic models and why they should be designed. In this article I discuss the general learnings from developing and deploying semantic models</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>If you are doing it all by yourself, it is not enterprise grade</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">As discussed in Part 1 these are the following people I collaborated with while building enterprise grade semantic models for a major superannuation company in Australia</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li style="list-style-type: none;">
<ul>
<li>Information Architects</li>
<li>Solution Architects</li>
<li>Data Stewards</li>
<li>Product Champions</li>
<li>Data Modelers</li>
<li>Business Analysts</li>
<li>Business Intelligence Developers</li>
<li>Testers</li>
<li>Delivery Managers</li>
<li>Report Developers</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">It truly does take a team to ideate, design, test, validate, and support the build of enterprise grade semantic models. In the past, I have developed pseudo enterprise grade models as I was donning multiple hats and that resulted in a not optimal data warehouse and subsequently the semantic model wasn&#8217;t fit for reporting. Hence is important to have specialists for the above roles. If you have built a semantic model by yourself, it is probably not enterprise grade. This leads to the next point</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Designing a report for an enterprise is not the same as semantic modeling</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">Many Power BI consultants make the mistake of interpreting a report built for a business unit in an enterprise as enterprise grade semantic models. They are not one and the same. Firstly, the reports have been probably built by a single person meaning, the person building the report is the architect, data modeler, data engineer, semantic modeler, and a report developer all rolled into one. It is akin to building the Burj Khalifa all by yourself, simply not possible when you deal with enterprise data.</p>
<p style="padding-left: 80px;">That doesn&#8217;t mean you should not build Power BI models for enterprises. But due to the localised nature of it, the models will only be used by a section of the end users and the rest of them won&#8217;t have a clue about it. Enterprise models should be available to be consumed (via reports) by all employees within the organisation. Only then can you call the models truly enterprise grade.</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Semantic model is not the same as a data warehouse</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">A data warehouse is built to standards conforming to the industry business unit from which the data is sourced. It is usually designed using dimension modelling using techniques of conformed dimensions, slowly changing dimensions, enterprise bus matrix etc. However, it may not always be used as is by the business for reporting. For starters the field names in the data warehouse may be something like &#8220;MemberAccountBalance_Total&#8221;, which may not mean much to the business. However, in the semantic model you can change it to something like &#8220;Member Account Balance&#8221; which is understandable for everyone.</p>
<p style="padding-left: 80px;">The other reason is more important. The fact tables in the data warehouse in most cases cannot be used directly to extract the corporate measures. For ex: in Superannuation and Banking industries, one of the most important measures is the Member Count, both current and historical. The Member Counts here represent Members who have an account in the superannuation or banking organisation. The Member Count should be increasing over time as that means the company is growing and is able to make a profit. This measure is normally not modelled as a field in the fact table in the data warehouse. Hence a semantic layer view needs to be created so that this measure is derived by say joining the Member dimension (which has information on all member attributes) with other fact tables like MemberBalanceSnapshot table (which has information on members who have accounts) along with the required dimensions so that it can be sliced appropriately.</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Be prepared for multiple iterations</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">If you are building a semantic model for the first time, you will probably need a few iterations to get it right. The model which you ultimately choose will be the one which has the right granularity for corporate reporting, has the business approved field names, simpler DAX expressions, refreshes faster, queries faster and is well documented. It is recommended to start the iteration process by focusing on the correct field names, table names, measure names and definitions and begin by designing a high-fidelity prototype with the important fact, dimension tables and measures. The prototype should be parameterised so it can be deployed to different environments easily. This way you will have a version which will be ready to scale when you deploy the final model for production.</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Semantic modeling is not technically difficult</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">While the job of a semantic modeler is technically not that demanding, say as compared to a data engineer it is probably the role with the most exposure to all stakeholders. You are like a conduit between the business and the technical team. You are constantly fielding questions on the semantic model from the report developers/business, and it is your job to make sure their questions are answered satisfactorily.</p>
<p style="padding-left: 80px;">Requirements for new tables, columns, measures may come thick and fast and that is why it is critical to ask the right questions so that these requirements can be formalised through a demand portal and taken up by the technical team based on their priorities. Which brings us to the next point&#8230;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Have an excellent relationship with all relevant stakeholders</h5>
</li>
</ul>
</li>
</ul>
<p style="padding-left: 80px;">Because a semantic modeler sits between business and the technical team, they should maintain excellent relationships with all parties involved. They should not only be adept at talking to the data modelers and architects on things like measure definitions, table grain, memory usage, processing times etc. they should also be skillful at explaining the model in simple terms while talking to business.</p>
<p style="padding-left: 80px;">You need to be persuasive to make your point while also seeking clarity to better inform your decision-making process. These are some of the soft skills which you need to master in order to be successful in this role.</p>
<ul>
<li style="list-style-type: none;"></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Musings from developing and deploying enterprise grade semantic models &#8211; Part 1: Introduction</title>
		<link>https://capstoneanalytics.com.au/learnings-from-developing-enterprise-grade-semantic-models/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=learnings-from-developing-enterprise-grade-semantic-models</link>
					<comments>https://capstoneanalytics.com.au/learnings-from-developing-enterprise-grade-semantic-models/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Fri, 21 Oct 2022 01:12:36 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Enterprise Semantic Model]]></category>
		<category><![CDATA[Semantic Layer]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2834</guid>

					<description><![CDATA[For the past one year, I have been fortunate enough to work on a digital transformation project for one of Australia&#8217;s largest superannuation funds to develop enterprise grade semantic models. I worked with a wonderful team comprising Solution Architects, Information Architects, Data Modelers, Data Stewards, Product Champions, Business Intelligence Analysts, Testers, Report Developers, and Delivery [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>For the past one year, I have been fortunate enough to work on a digital transformation project for one of Australia&#8217;s largest superannuation funds to develop enterprise grade semantic models. I worked with a wonderful team comprising Solution Architects, Information Architects, Data Modelers, Data Stewards, Product Champions, Business Intelligence Analysts, Testers, Report Developers, and Delivery Managers to ideate, design, test, deploy, and document semantic models which contained superannuation data for the funds&#8217; members. It was an exciting project with lots of challenges and lots of learnings. So I thought I would make a blog post to share the learnings with everybody.</p>
<p>Firstly, what is a semantic model ? Before we get to the semantic model we need to understand its relationship with respect to the semantic layer. According to Wikipedia:</p>
<p style="text-align: center;"><em>A <b>semantic layer</b> is a business representation of corporate data that helps end users access data autonomously using common business terms. A semantic layer maps complex data into familiar business terms such as product, customer, or revenue to offer a unified, consolidated view of data across the organization</em></p>
<p>The above definition is as good as it gets without the use of unnecessary jargon. So we will stick with this going forward. Where does the semantic layer sit in a modern BI/analytics landscape. The below simplified architecture answers the question. This is for a Power BI landscape but would work similarly with other tools.</p>
<p><img loading="lazy" decoding="async" class=" wp-image-2847 alignnone" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/09/model-framework.png" alt="" width="1141" height="271" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/09/model-framework-980x233.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/09/model-framework-480x114.png 480w" sizes="auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1141px, 100vw" /></p>
<p>&nbsp;</p>
<p>So as you can see, the semantic layer is that layer which sits between the data warehouse (which is the output of the Transformation Layers) and the reporting layer. The semantic layer consists of two parts</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>Semantic Layer DB &#8211; These are the SQL views which are created in the database from the Fact and Dimension tables. The views can be a one-to-one copy of the tables or they can be enhanced with fields containing report level logic. It is in these views that business friendly names are given to the fields. So instead of &#8216;MemberName&#8217; we would have &#8216;Member Name&#8217; as a field. It is important that no business transformations are applied in the views. All transformations are to be applied in the transformation layers and the data loaded to the data warehouse.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>Semantic Model PBI &#8211; The views are imported into a Power BI Desktop model which is called the semantic model. Corporate measures, which have been defined by data stewards are then calculated in the model. Most of these measures are simple aggregations of fields in the tables (SUM, DISTINCTCOUNT). The semantic model is then published to PBI service where report developers connect to it, design reports and share via apps. The semantic model is the &#8216;single version of truth&#8217; and is used as the primary data source for enterprise reports. In this example, all superannuation related reports would connect to this model to generate insights. It is the design and deployment of this semantic model which would be the focus of this series of blogs.</li>
</ul>
</li>
</ul>
<p>So in essence, in the PBI world, the semantic model is a dataset with corporate measures, used to query organisational metrics. The reports which query the dataset are in fact &#8216;Thin Reports&#8217;, with the report developers having the ability to create report level measures. In the simplest architecture the dataset contains many datamarts and the data is imported into the model. All datamarts have a star schema associated with them.</p>
<p>So why build the semantic model after all ? There are several reasons why an organisation should implement a semantic model. The key reasons are given below</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Single Version of Truth (SVOT)</h5>
<p>When implemented correctly, the semantic model provides accurate and trustworthy data for key organisational metrics which serve as the SVOT no matter which tool is used to query it. Because the metrics have been defined in consultation with relevant stakeholders from the business, any report connecting to the model and querying the metrics (in the form of measures) produces the same result. This is quite powerful as there is no longer confusion on what the metrics mean, and everyone will be on the same page discussing the reports.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Seamless collaboration</h5>
<p>A semantic model allows for creation of a data model which is a visual description of the business for analyzing, understanding, and clarifying the data and the associated relationships. This model can not only be used by the business to generate insights but can also be used by data scientists to complement the raw data which they use in their models. Composite models, which are models which are created by combining the semantic model with business unit specific data (say salary data) can also be created and shared with the relevant stakeholders. Thus the creation of the semantic model enables easy authoring, sharing, and collaborating of data models and insights.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Reduce computing costs</h5>
<p>With most business running their data warehouses in the cloud, ad-hoc querying the data warehouse for every report leads to poor workload management and long running queries being run multiple times. With a cached semantic model, only optimised queries (via views) which are at the grain required for business reporting are run, which improves query performance and reduces costs.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Simplify DAX calculations</h5>
<p>The semantic model is structured in such a way that measures in the model are simple aggregations of the columns in the views. Since all the transformations are done prior to data being loaded into the data warehouse and report specific logic being implemented in the views, writing DAX to create either the corporate measures or report level measures becomes easier. This is why it is important to have solution architects and data modelers in your team who would make sure that the views are at the right grain and fit for purpose for reporting.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Improved security</h5>
<p>Users can be authenticated to use the semantic model with Azure AD groups and further, Row Level Security can be implemented at both the DB level and at the dataset level to protect sensitive data and limit access to data for users based on their roles in the organisation.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<p>So what constitutes an enterprise grade semantic model ? In my opinion, the following conditions should be satisfied for a model to be classified as enterprise grade</p>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Represent data from a business unit</h5>
<p>The semantic models which I designed enabled end users to query data related to the members of the superannuation fund. Metrics such as Member Count, Exited Member Count,Member Account Balance, New Join Count etc could be queried from the model by slicing them with dimensions such as Member, Age Bracket, Employer, Payment Institution, Amount Bracket etc. In short, the relevant business unit in this case was Superannuation and the semantic model contained almost all the data required by the business to attract and retain members into the fund. Normally there is an executive sponsor who funds the project to set the ball rolling.</p>
<p>&nbsp;</li>
<li>
<h5>Governed corporate measures</h5>
<p>It doesn&#8217;t make sense to model the data from a business unit if there is no consensus on the definitions of the corporate metrics. It is important that even before conceptualising the data platform, a thorough process is undertaken to define the most important corporate metrics and get them approved by the relevant stakeholders. This can be facilitated by setting up a Data Office in the organisation which is responsible for signing off on the corporate measures based on the approved definitions from the stakeholders.</p>
<p>&nbsp;</li>
<li>
<h5>Architecting the solution</h5>
<p>So, you have identified which business unit&#8217;s data to model and have also got sign offs on the corporate metrics which need to be the output of the model. It is then critical to start brainstorming on how the solution would look like. This is where the Architects come into play. Most enterprise data reside in databases in different source systems. The architects will perform a detail analysis on what is the current state of the source systems, the best way to extract the data from the source systems, selecting the appropriate cloud platform for the solution, and designing the conceptual and logical design in tandem with the Data Modelers. The data warehouse is then built by the data engineers based on the specifications given to them by the Data Modeler. The semantic model is then designed from the data in the data warehouse based on the reporting requirements of the business. One of the core architectural principles is that any reusable logic (columns) should be applied as close to the source as practical. ie, there should be no columns defined in Power Query or in the Power BI model. If the solution is not architected, then it is not an enterprise grade model.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li>
<h5>Deliver fast queries</h5>
<p>Once the solution is architected and the corporate measures have been defined in the model based on the business definitions, it is time to deploy the model. If the reports connecting to the semantic model cannot query a measure in less than 3 seconds (nothing scientific about measures being able to run in less than 3 seconds, just a number which was felt good enough at the time of deployment), then it is time to go back to the drawing board. The semantic model should be fast enough to respond to the needs of the business. A slow model will impede adoption and people will lose trust in the efficacy of the model.</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<p>Hopefully this article has piqued your interest in all things enterprise semantic modelling using Power BI &#8211; They Why&#8217;s and the What&#8217;s. In the next series of articles, I will share about the learnings I gained from developing and deploying enterprise grade semantic models. Some will be <a href="https://capstoneanalytics.com.au/musings-from-developing-and-deploying-enterprise-grade-semantic-models-part2-general-learnings/">general</a>, and others will be technical. Hope you find them useful too.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/learnings-from-developing-enterprise-grade-semantic-models/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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>The eleven rules of DAX management</title>
		<link>https://capstoneanalytics.com.au/the-eleven-rules-of-dax-management/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-eleven-rules-of-dax-management</link>
					<comments>https://capstoneanalytics.com.au/the-eleven-rules-of-dax-management/#respond</comments>
		
		<dc:creator><![CDATA[Abhijith DSouza]]></dc:creator>
		<pubDate>Fri, 04 Mar 2022 12:35:08 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<category><![CDATA[DAX]]></category>
		<category><![CDATA[Seven Principles of DAX Management]]></category>
		<guid isPermaLink="false">https://capstoneanalytics.com.au/?p=2719</guid>

					<description><![CDATA[There are several articles and books written on how to write better DAX and I have written a fair few as well. This article is not one of them. What will cover in this article are some of the best practices associated with DAX management and housekeeping before we deploy our models to production. They [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>There are several articles and books written on how to write better DAX and I have written a fair few as well. This article is not one of them. What will cover in this article are some of the best practices associated with DAX management and housekeeping before we deploy our models to production. They are all important, so make sure to tick them off before you release anything to production</p>
<p>&nbsp;</p>
<ul>
<li><strong><strong><strong>Use Explicit measures and not Implicit measures</strong></strong></strong></li>
</ul>
<p style="padding-left: 40px;">It still amazes me that I come across Power BI models developed by developers who still use implicit measures in their production ready models. Even if you do not follow the other 6 principles, this one simply cannot be skipped. So what are implicit and explicit measures ? Implicit measures are those which make use of the default summarization properties of columns (sum, average, count, max, min etc) to populate a visual. You can drag and drop a column into the &#8216;Fields&#8217; or &#8216;Values&#8217; section of a visual and set its summarization type to get your result. As you can see below the Production column has a default summarization set to SUM and is dragged into a card visual and the name changed to &#8216;Tonnes&#8217; and the visual is populated. Why is this bad ?</p>
<p style="padding-left: 40px;">The default summarization could have been set to SUM but it could have been changed to AVERAGE when placed under Fields. It&#8217;s very hard to audit what the measure is calculating without looking at each column and each visual which can become tedious</p>
<p style="padding-left: 40px;">Complex measures cannot be defined this way as only basic summarizations are allowed.</p>
<p style="padding-left: 40px;">The measure cannot be reused since its not explicitly defined.</p>
<p style="padding-left: 40px;">It cannot be accessed via external tools like Excel, as only explicit measures are visible in those tools.</p>
<p style="padding-left: 40px;"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2759" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.2.png" alt="" width="1864" height="801" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.2.png 1864w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.2-1280x550.png 1280w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.2-980x421.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.2-480x206.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) 1864px, 100vw" />So then, what are explicit measures ? Explicit measures are the default way measures should be defined in Power BI. And we do that by explicitly writing out the formula in DAX. To redo the above example we write a measure called</p>
<p style="padding-left: 40px;">Tonnes = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Fact Production'[Production] <span class="Parenthesis" style="color: #808080;">)</span></p>
<p style="padding-left: 40px;">and place it under &#8216;Fields&#8217; in the card visual. You can see that there is a clear lineage between the measure definition and the output. Explicit measures are auditable, they can be reused inside other measures, you can author complex DAX measures and other tools like Excel can see them in their environments</p>
<p style="padding-left: 40px;"><img loading="lazy" decoding="async" class="alignnone wp-image-2760" src="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.3.png" alt="" width="1293" height="556" srcset="https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.3.png 1293w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.3-1280x550.png 1280w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.3-980x421.png 980w, https://capstoneanalytics.com.au/wp-content/uploads/2022/03/DAX-Management-1.3-480x206.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) 1293px, 100vw" /></p>
<p>&nbsp;</p>
<ul>
<li><strong>Use Consistent Naming Conventions</strong></li>
</ul>
<p style="padding-left: 40px;">Follow a consistent naming convention so that its easier to read. In my projects I tend to use Proper Case , so I would write &#8216;Sales Amount&#8217; instead of &#8216;Sales amount&#8217;. This is not a hard and fast rule though. But whatever convention you choose adopt it consistently.</p>
<p>&nbsp;</p>
<ul>
<li><strong><strong><strong><strong>Measures should be performant</strong></strong></strong></strong></li>
</ul>
<p style="padding-left: 40px;">Once you have finished authoring explicit DAX measures, and placed them in visuals you need to ensure that they are performant. What does that mean ? You need to ensure that your visuals on a page are loading quickly (not more than 3 seconds) and that the DAX code is not taking long to execute. Thee is nothing worse than designing awesome looking dashboards if the end users find it frustrating to use as it takes a long time for the visuals to load as the DAX code is being executed in the background. This post will not cover how to optimise DAX code as other people have covered it extensively. A good starting point is to use the Performance Analyzer in Power BI and determine which measures are taking the longest to execute and copy the DAX query into <a href="https://daxstudio.org/">DAX Studio</a> for further investigation.</p>
<p>&nbsp;</p>
<ul>
<li><strong><strong>Format the code</strong></strong></li>
</ul>
<p style="padding-left: 40px;">If its not formatted, its not DAX. Consider the code below</p>
<p>&nbsp;</p>
<div>
<p style="padding-left: 40px;">Average Sales Per Store  = VAR t1 = ADDCOLUMNS ( SUMMARIZE ( FactOnlineSales, DimStore[StoreName] ), &#8220;TotalSales&#8221;, CALCULATE ( SUMX ( FactOnlineSales, FactOnlineSales[SalesQuantity] * FactOnlineSales[UnitPrice] &#8211; FactOnlineSales[DiscountAmount] ), FactOnlineSales[SalesQuantity] &gt; 0 ) ) RETURN AVERAGEX ( t1, [TotalSales] )</p>
<p style="padding-left: 40px;">Its a lengthy piece of code and its hard to understand what&#8217;s going on. So if you find the code hard to read, imagine how hard would it be for someone else who would inherit the model. So do the right thing and format the code using <a href="https://www.daxformatter.com/">DAX formatter</a>. The formatted code below is cleaner and easier to read and audit</p>
<p>&nbsp;</p>
<p style="padding-left: 40px;">Average Sales Per Store =<br />
<span class="Keyword" style="color: #035aca;">VAR</span> <span class="Variable" style="color: #49b0af;">t1</span> =<br />
<span class="Keyword" style="color: #035aca;">ADDCOLUMNS</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<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>,<br />
<span class="StringLiteral" style="color: #d93124;">&#8220;TotalSales&#8221;</span>,<br />
<span class="Keyword" style="color: #035aca;">CALCULATE</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
<span class="Keyword" style="color: #035aca;">SUMX</span><span class="Parenthesis" style="color: #808080;"> (</span><br />
FactOnlineSales,<br />
FactOnlineSales[SalesQuantity] * FactOnlineSales[UnitPrice] &#8211; FactOnlineSales[DiscountAmount]<br />
<span class="Parenthesis" style="color: #808080;">)</span>,<br />
FactOnlineSales[SalesQuantity] &gt; <span class="Number" style="color: #ee7f18;">0</span><br />
<span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Keyword" style="color: #035aca;">RETURN</span><br />
<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></p>
</div>
<p>&nbsp;</p>
<div>
<ul>
<li><strong>Format your measure</strong></li>
</ul>
<p style="padding-left: 40px;">It is not just important to format your code, it is also important to format the measure itself. Measures can be formatted as Text, General, Currency, Whole number, Decimal Number, Percentage or Scientific. Use the appropriate formatting for each measure.</p>
</div>
<p>&nbsp;</p>
<ul>
<li><strong><strong><strong>Use comments</strong></strong></strong></li>
</ul>
<p style="padding-left: 40px;">Use comments in code to clarify any assumptions made, on which page the measure is being used, if its a temporary measure etc. To activate comments, in a new line in the DAX editor window in Power BI press &#8216;Ctrl /&#8217; and then type your comments. Below is an example. This makes it easier for you to know where your measures are being used and if they are being used at all.</p>
<p style="padding-left: 40px;">Tonnes = <span class="Keyword" style="color: #035aca;">SUM</span><span class="Parenthesis" style="color: #808080;"> (</span> &#8216;Fact Production'[Production] <span class="Parenthesis" style="color: #808080;">)</span><br />
<span class="Comment" style="color: #39a03b;">// This is used in the Executive Summary page</span></p>
<p>&nbsp;</p>
<ul>
<li><strong><strong>Provide a description and synonyms</strong></strong></li>
</ul>
<p style="padding-left: 40px;">A description of what the measure stands for is very useful especially if the model is being used to develop multiple reports. Usually, in corporate a base set of measures will have been defined and validated by the data stewards and data custodians and you can find them in a sharepoint page or confluence page. Copy those definitions and paste them under the description section of the measure. If there are synonyms used make sure to copy them as well.</p>
<p>&nbsp;</p>
<ul>
<li><strong>Apply appropriate data category</strong></li>
</ul>
<p style="padding-left: 40px;">If your measure denotes an address like country or city you can apply the appropriate data category for it. This is important when you want to use the measure in geo spatial visuals so that the visuals correctly identify the location. If you measure contains an URL make sure to either apply a Web URL or an Image URL.</p>
<p>&nbsp;</p>
<ul>
<li><strong><strong>Test measures against the source</strong></strong></li>
</ul>
<p style="padding-left: 40px;">This is especially important in enterprise semantic models where the source of the data is from a database/data warehouse. In such cases you can readily test the outputs of the measures against the equivalent SQL queries from the tables/views. You can automate this by running a testing framework in Azure by calling the <a href="https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries"><strong>Dataset Execute Queries REST API .</strong></a></p>
<p>&nbsp;</p>
<ul>
<li><strong>Place the measures in a dedicated measure table</strong></li>
</ul>
<p style="padding-left: 40px;">Placing the measures in a dedicated measure table ensure easy access to all the measures. You can call the table something like &#8216;ALL MEASURES&#8217;, &#8216;BASE MEASURES&#8217;, &#8216;REPORT MEASURES&#8217; etc. You can also group them into different folders for ease of navigation.</p>
<p>&nbsp;</p>
<ul>
<li><strong>Document your code</strong></li>
</ul>
<p style="padding-left: 40px;">Finally it is important to document all the measures you have written in your model or report once you have finalised it. The documented code serves as a final repository of all your DAX which can be easily accessible. There are no automated ways to document your code but tools like <a href="https://powerbihelper.org/">Power BI helper</a> can help you in the journey.</p>
<p>&nbsp;</p>
<p>You can download a handy pdf reference guide of the eleven rules below</p>
<p><a href="https://drive.google.com/u/0/uc?id=1bSCDe92asBAoLdTW4JQ6kgDxjKjAyOc3&amp;export=download">Eleven rules of DAX management</a></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://capstoneanalytics.com.au/the-eleven-rules-of-dax-management/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>
	</channel>
</rss>
