<?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 Make Subtotal use Average instead of Sum in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717290#M35498</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compute a weighted average and while each row of the matrix is following the DAX i created, the subtotal for each group is doing some sort of sum. Not only do i not understand what sum it is doing but what i want is the Average of each entry in the group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general idea is to get the full year of the budgetted availability weighted by the number of days in each month. This value should be the same regardless of the month picked in slicers, it isn't a YTD sort of year. The DAX is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FullYear = 
        var MultSum = CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    var SumDays = CALCULATE(COUNTROWS('Calendar Table'), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    return  MultSum / SumDays&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recreated my issue in a simple example. I would post the files but i can figure out how to import them here. Essentially, for the "one Letter" group, the "FullYear" value should have been 95.94%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Report &amp;amp; Data examples:&lt;/P&gt;&lt;P&gt;[Snapshots]&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 19:37:22 GMT</pubDate>
    <dc:creator>DFC</dc:creator>
    <dc:date>2021-03-11T19:37:22Z</dc:date>
    <item>
      <title>Make Subtotal use Average instead of Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717290#M35498</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compute a weighted average and while each row of the matrix is following the DAX i created, the subtotal for each group is doing some sort of sum. Not only do i not understand what sum it is doing but what i want is the Average of each entry in the group.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The general idea is to get the full year of the budgetted availability weighted by the number of days in each month. This value should be the same regardless of the month picked in slicers, it isn't a YTD sort of year. The DAX is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FullYear = 
        var MultSum = CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    var SumDays = CALCULATE(COUNTROWS('Calendar Table'), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    return  MultSum / SumDays&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recreated my issue in a simple example. I would post the files but i can figure out how to import them here. Essentially, for the "one Letter" group, the "FullYear" value should have been 95.94%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Report &amp;amp; Data examples:&lt;/P&gt;&lt;P&gt;[Snapshots]&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 19:37:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717290#M35498</guid>
      <dc:creator>DFC</dc:creator>
      <dc:date>2021-03-11T19:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: Make Subtotal use Average instead of Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717305#M35500</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="171551" data-lia-user-login="DFC" class="lia-mention lia-mention-user"&gt;DFC&lt;/a&gt;&amp;nbsp;This looks like a measure totals problem. Very common. See my post about it here: &lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376" target="_blank"&gt;https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907" target="_blank"&gt;https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you may find this helpful as well:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Matrix-Measure-Total-Triple-Threat-Rock-amp-Roll/td-p/411443" target="_blank"&gt;Matrix Measure Total Triple Threat Rock &amp;amp; Roll - Microsoft Power BI Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 19:53:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717305#M35500</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2021-03-11T19:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Make Subtotal use Average instead of Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717541#M35507</link>
      <description>&lt;P&gt;I followed your suggestion,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;,&amp;nbsp; of the IF( HASONEFILTER(...)) and it worked. However, I feel like i just "hammered" the right answer onto the report when there's probably a better DAX to be used. Could you correct my DAX especially for the case where HASONEFILTER is false.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;FullYear_subtot = 
        var MultSum = CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

        var SumDays = CALCULATE(COUNTROWS('Calendar Table'), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

        return IF(
                    HASONEFILTER(Sheet1[Type]),
                    MultSum / SumDays,
                    CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Sheet1'), VALUES('Sheet1'[Group]), VALUES('Calendar Table'[Year])) / (SumDays * CALCULATE(DISTINCTCOUNT(Sheet1[Type]), VALUES(Sheet1[Group])))
                    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I would accept your answer as the correct one immediately but im not sure if that wont shut down the whole thread and Id like to have some feedback from you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for pointing me tot he right direction.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 00:33:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Make-Subtotal-use-Average-instead-of-Sum/m-p/1717541#M35507</guid>
      <dc:creator>DFC</dc:creator>
      <dc:date>2021-03-12T00:33:20Z</dc:date>
    </item>
  </channel>
</rss>

