<?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>Power BI &#8211; Cognim &#8211; Internet development</title>
	<atom:link href="https://www.cognim.co.uk/category/power-bi/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.cognim.co.uk</link>
	<description>Enterprise system implementation. Making the complex simple</description>
	<lastBuildDate>Tue, 18 Aug 2015 15:36:35 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">91553907</site>	<item>
		<title>Power BI &#8211; Quick Tip. Percent of Total</title>
		<link>https://www.cognim.co.uk/power-bi-quick-tip-percent-of-total/</link>
					<comments>https://www.cognim.co.uk/power-bi-quick-tip-percent-of-total/#comments</comments>
		
		<dc:creator><![CDATA[Darren Hall]]></dc:creator>
		<pubDate>Tue, 18 Aug 2015 15:36:35 +0000</pubDate>
				<category><![CDATA[Power BI]]></category>
		<guid isPermaLink="false">http://www.cognim.co.uk/?p=5203</guid>

					<description><![CDATA[If you need to add &#8216;Percent of Total&#8217; to your charts in Power BI, here&#8217;s how.. Microsoft&#8217;s Power BI is excellent.  It is so easy to get up and running with data coming from a multitude of places. Out of the box you can easily show facts and figures related to your data.  One thing [&#8230;]]]></description>
										<content:encoded><![CDATA[<h3>If you need to add &#8216;Percent of Total&#8217; to your charts in Power BI, here&#8217;s how..</h3>
<p>Microsoft&#8217;s Power BI is excellent.  It is so easy to get up and running with data coming from a multitude of places. Out of the box you can easily show facts and figures related to your data.  One thing it currently misses though is a &#8216;percent of total&#8217; aggregation for measures.</p>
<p>Recently I wanted to show browser usage for visitors to a web based questionnaire. The client had asked to see the browsers ordered by popularity with their respective percentage share displayed.</p>
<p>The SQL Server table &#8216;Dim_Respondents&#8217; had the following columns available: LocalRespondentId (unique integer), Browser (text), DateStarted (Date) plus some foreign key references to other tables I could filter by such as Questionnaire Name, Questionnaire Status etc.  It was easy to get the browser count with a horizontal bar chart as follows</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/SimpleBrowserChart.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5215 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/SimpleBrowserChart.png?resize=800%2C870&#038;ssl=1" alt="Simple Power BI chart by count" width="800" height="870" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/SimpleBrowserChart.png?w=800&amp;ssl=1 800w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/SimpleBrowserChart.png?resize=276%2C300&amp;ssl=1 276w" sizes="auto, (max-width: 800px) 100vw, 800px" /></a></p>
<p>Notice how I have just added Browser to the Axis and &#8216;Count of LocalRespondentId&#8217; to the Value.  The difficulty comes in trying to get percentages because you can only aggregate your data by sum, average, minimum, maximum and count.  The closest you can come is a 100% stacked bar chart;</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/BrowserStackedChart.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5216 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/BrowserStackedChart.png?resize=800%2C870&#038;ssl=1" alt="Power BI stacked bar chart" width="800" height="870" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/BrowserStackedChart.png?w=800&amp;ssl=1 800w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/BrowserStackedChart.png?resize=276%2C300&amp;ssl=1 276w" sizes="auto, (max-width: 800px) 100vw, 800px" /></a></p>
<p>but with a lot of browsers that is not a workable option.  Luckily Power BI lets us create our own measures using DAX. To do so , you need to right-click on your data table and select &#8216;New Measure&#8217;.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NewMeasure.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5217 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NewMeasure.png?resize=365%2C374&#038;ssl=1" alt="Power BI - Create a new measure" width="365" height="374" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NewMeasure.png?w=365&amp;ssl=1 365w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/NewMeasure.png?resize=293%2C300&amp;ssl=1 293w" sizes="auto, (max-width: 365px) 100vw, 365px" /></a></p>
<p>You can then enter your measure name and a DAX expression. (<a href="https://support.powerbi.com/knowledgebase/articles/554619-dax-basics-in-power-bi-desktop">See &#8216;DAX basics in Power BI Desktop&#8217;</a> for basic DAX information). For our purposes we would like to know the number of respondents with a particular browser divided by the total number of respondents.  Before I create the measure though we need to consider that it is highly likely that this chart will have been further filtered &#8211; maybe by date or something else. Our calculation must take that into account.  The easiest way to express it is to say that we need the number of respondents for a particular browser taking into account all applied filters divided by the number of respondents for all browsers taking into account all applied filters (sorry, I know that is a long-winded statement, but bear with me).</p>
<p>In DAX we can write &#8216;<span class="lang:c# decode:true  crayon-inline ">COUNTA(Dim_Respondents[Browser])</span> &#8216; for the first part which is simple enough (basically counts the number of values in a column after all filters have been applied &#8211; and remember that we have Browser on an axis so we are effectively filtering by Browser for each chart position), but the second part is a little more tricky. We can solve it by using &#8216;<span class="lang:c# decode:true  crayon-inline ">CALCULATE(COUNTROWS(Dim_Respondents),ALL(Dim_Respondents[Browser]))</span> &#8216; which says calculate the first expression &#8216;COUNTROWS(Dim_Respondents)&#8217; for the second filtered data set &#8216;ALL(Dim_Respondents[Browser])&#8217;. The &#8216;ALL(..)&#8217; statement clears the filter for the mentioned column so in our case ignores the axis filter on Browser and gives us a total count. The whole expression is</p>
<pre class="lang:c# decode:true ">Browser % = COUNTA(Dim_Respondents[Browser]) / CALCULATE(COUNTROWS(Dim_Respondents),ALL(Dim_Respondents[Browser]))</pre>
<p>Note that I haven&#8217;t multiplied the answer by 100 because it is better to click your new measure and set its format type to &#8216;Percentage&#8217; in the Modeling tab.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/FormatAsPercentage.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5218 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/FormatAsPercentage.png?resize=422%2C123&#038;ssl=1" alt="Power BI - Format measure as percentage" width="422" height="123" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/FormatAsPercentage.png?w=422&amp;ssl=1 422w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/FormatAsPercentage.png?resize=300%2C87&amp;ssl=1 300w" sizes="auto, (max-width: 422px) 100vw, 422px" /></a></p>
<p>You can now replace the count of LocalrespondentId directly with your new measure and set your chart to sort by the percentage;</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartByPercent.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5219 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartByPercent.png?resize=885%2C900&#038;ssl=1" alt="Power BI - Chart by Percentage" width="885" height="900" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartByPercent.png?w=885&amp;ssl=1 885w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartByPercent.png?resize=295%2C300&amp;ssl=1 295w" sizes="auto, (max-width: 885px) 100vw, 885px" /></a></p>
<p>One last nice touch is to put the percentages on the graph by setting Data Labels to &#8216;on&#8217;.</p>
<p><a href="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartWithDataLabels.png?ssl=1"><img data-recalc-dims="1" decoding="async" loading="lazy" class="aligncenter wp-image-5220 size-full" src="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartWithDataLabels.png?resize=885%2C900&#038;ssl=1" alt="Power BI - Chart with data labels" width="885" height="900" srcset="https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartWithDataLabels.png?w=885&amp;ssl=1 885w, https://i0.wp.com/www.cognim.co.uk/wp-content/uploads/2015/08/ChartWithDataLabels.png?resize=295%2C300&amp;ssl=1 295w" sizes="auto, (max-width: 885px) 100vw, 885px" /></a></p>
<p>Hope this helps!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.cognim.co.uk/power-bi-quick-tip-percent-of-total/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">5203</post-id>	</item>
	</channel>
</rss>
