<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculate sum or squares of column percentage values in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649786#M33570</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;This is very close to what I'm looking to do. It calculates HHI correctly for the Market and SubSegment categories. The only thing it isn't doing is filtering by year. If I use Year for Columns in matrix visual, I get identical values for both 2018 and 2019. These are aggregate values for all years.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;While I can add a slicer, I'd like to see the year-over-year change. Is there a way to do both rowwise and columnwise filtering?&lt;/P&gt;</description>
    <pubDate>Sun, 07 Feb 2021 06:09:32 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-02-07T06:09:32Z</dc:date>
    <item>
      <title>Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649729#M33565</link>
      <description>&lt;P&gt;I'm working with market data, and I'm trying to use DAX to calculate the&amp;nbsp;&lt;SPAN&gt;Herfindahl-Hirschman Index (&lt;/SPAN&gt;&lt;A href="https://www.investopedia.com/terms/h/hhi.asp" target="_blank" rel="noopener"&gt;HHI&lt;/A&gt;&lt;SPAN&gt;) for different markets. This is a measure of market concentration, and it calculated as the sum of the squares of market share for each vendor. Here's an example market:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Vendor&lt;/TD&gt;&lt;TD&gt;Revenue&lt;/TD&gt;&lt;TD&gt;Market Share&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;12.5%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;25.0%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;62.5%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;So the HHI would be (12.5*12.5 + 25*25 + 62.5*62.5) = 4867.5. (For HHI, each percentage value is multiplied by 100.)&lt;/P&gt;&lt;P&gt;I have vendor revenue data by year, market, and submarket. I'd like to be able to calculate HHI at both the market and submarket level.&lt;/P&gt;&lt;P&gt;I can create a matrix visual by summarizing revenue per vendor as a percent of the column total, where each column is the market I'm trying to calculate the HHI for. In Excel, I calculate HHI manually using the SUMPRODUCT of the column of market share by market with itself to get the sum of squares.&amp;nbsp;&lt;SPAN&gt;I'm having trouble coming up with a DAX measure or a new table to calculate HHI, though. I've tried SUMMARIZE and GROUPBY, but I'm stuck.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Here is a link to a .pbix file with sample data:&amp;nbsp;&lt;A href="https://1drv.ms/u/s!AgIj2L_vt8Wrg_B2jTCa8MduAaXS8A?e=HVX84o" target="_blank" rel="noopener"&gt;https://1drv.ms/u/s!AgIj2L_vt8Wrg_B2jTCa8MduAaXS8A?e=HVX84o&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 00:39:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649729#M33565</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-07T00:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649760#M33566</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how I would create a measure for HHI using the data in your PBIX (thanks for sharing by the way).&lt;/P&gt;
&lt;P&gt;My modified PBIX is attached with an extra tab showing HHI.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First create a Revenue measure to make the code more readable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Revenue = 
SUM ( 'Market Data'[Revenue - USD] )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create this HHI measure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;HHI = 
VAR TotalRevenueSquared = [Revenue] ^ 2
VAR RevenueSquaredSumPerVendor =
    SUMX ( VALUES ( 'Market Data'[Vendor] ), [Revenue] ^ 2 )
RETURN
    DIVIDE ( RevenueSquaredSumPerVendor, TotalRevenueSquared ) * 10 ^ 4&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The HHI measure assumes that the HHI is calculated over all Vendors visible in the current filter context, so you shouldn't include Vendor as a field on the visual where the HHI measure is displayed.&lt;/P&gt;
&lt;P&gt;Summary of steps:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Calculates the squared Revenue total (&lt;STRONG&gt;TotalRevenueSquared&lt;/STRONG&gt;)&lt;/LI&gt;
&lt;LI&gt;Sums the squared revenue per Vendor (&lt;STRONG&gt;RevenueSquaredSumPerVendor&lt;/STRONG&gt;)&lt;/LI&gt;
&lt;LI&gt;Divides 1 by 2, then multiplies by 10^4, which should be equivalent to the HHI definition.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 02:31:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649760#M33566</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2021-02-07T02:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649761#M33567</link>
      <description>&lt;P&gt;Here's your DAX. Pretty sure this can be optimized.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;HHI = &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var a = sumx('Market Data','Market Data'[Revenue - USD])&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var v = ADDCOLUMNS(VALUES('Market Data'[Vendor]),"V",'Market Data'[Vendor])&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var s = ADDCOLUMNS(v,"Share",Int(100*sumx(filter('Market Data','Market Data'[Vendor]=[V]),'Market Data'[Revenue - USD])/a))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;return sumx(s,[Share]*[Share])&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;img /&gt;
&lt;P&gt;Here's a shorter version:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;HHI2 = &lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var a = sumx('Market Data','Market Data'[Revenue - USD])/100&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var v = SUMMARIZE('Market Data','Market Data'[Vendor],"Share",int(sum('Market Data'[Revenue - USD])/a))&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;return sumx(v,[Share]*[Share])&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 07 Feb 2021 14:12:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649761#M33567</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-02-07T14:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649786#M33570</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;This is very close to what I'm looking to do. It calculates HHI correctly for the Market and SubSegment categories. The only thing it isn't doing is filtering by year. If I use Year for Columns in matrix visual, I get identical values for both 2018 and 2019. These are aggregate values for all years.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;While I can add a slicer, I'd like to see the year-over-year change. Is there a way to do both rowwise and columnwise filtering?&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 06:09:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649786#M33570</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-07T06:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649807#M33572</link>
      <description>&lt;P&gt;You're welcome&amp;nbsp;Anonymous&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you using the Year column from the 'Market Data' table (from the auto-generated date hierarchy)?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I use that column at my end, the filtering by Year appears to work as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Updated file attached.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 07:29:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1649807#M33572</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2021-02-07T07:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650022#M33577</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;Note that the HHI definition expects integer values for the individual market share.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 14:10:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650022#M33577</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-02-07T14:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650101#M33585</link>
      <description>&lt;P&gt;D'oh! That's embarassing.&lt;BR /&gt;Your solution does just what I needed. Thank you so much for your help.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 16:57:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650101#M33585</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-07T16:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650205#M33588</link>
      <description>&lt;P&gt;I believe HHI expects market share percentages multiplied by 100 (e.g., .234 = 23.4) but not necessarily integers. This becomes important when you have lots of small providers with less than 1% market share.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 19:23:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650205#M33588</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-07T19:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650233#M33589</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 19:59:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650233#M33589</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-02-07T19:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650246#M33590</link>
      <description>&lt;P&gt;I understand your point, but the phrase "as a whole number, not a decimal" is misleading. It really means that percentages are multiplied by 100. So again, 0.234 would be represented as 23.4, not 23.&lt;BR /&gt;I work with markets that have hundreds of vendors. Restricting in put to whole numbers would result in a total of more than 100% as well as many vendors with less than 0.5% listed as zero.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 20:26:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650246#M33590</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-07T20:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate sum or squares of column percentage values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650253#M33591</link>
      <description>&lt;P&gt;That's what the definition says that you pointed to, and it is also mentioned explicitly in Wikipedia.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;The Herfindahl Index (&lt;/SPAN&gt;&lt;I&gt;H&lt;/I&gt;&lt;SPAN&gt;) ranges from 1/&lt;/SPAN&gt;&lt;I&gt;N&lt;/I&gt;&lt;SPAN&gt;&amp;nbsp;to one, where&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;N&lt;/I&gt;&lt;SPAN&gt;&amp;nbsp;is the number of firms in the market. Equivalently, if percents are used as whole numbers, as in 75 instead of 0.75, the index can range up to 100&lt;/SPAN&gt;&lt;SUP&gt;2&lt;/SUP&gt;&lt;SPAN&gt;, or 10,000."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;They will have had a reason for this. It will never result in more than 100%, but yes, it will filter out anyone with less than 1% share. (or less than 0.5%&amp;nbsp; if you interpret "whole number"&amp;nbsp; and "rounded" rather than "rounded down").&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 20:38:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-sum-or-squares-of-column-percentage-values/m-p/1650253#M33591</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-02-07T20:38:43Z</dc:date>
    </item>
  </channel>
</rss>

