<?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: Sum of Average Sum in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674675#M34273</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest an AverageX for the inner average.&lt;/P&gt;
&lt;P&gt;Kind regards, Steve.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2021 12:11:33 GMT</pubDate>
    <dc:creator>stevedep</dc:creator>
    <dc:date>2021-02-18T12:11:33Z</dc:date>
    <item>
      <title>Sum of Average Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674605#M34269</link>
      <description>&lt;P&gt;Hi experts&lt;/P&gt;&lt;P&gt;Ive had a read around the forum and not quite found what I'm looking for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example table of data below. The table shows headcount by site (column is actually called 'Full Name'), each site is in a group. I am trying to calcuate the total headcount for the month.&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;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The steps involved to get total headcount are&lt;/P&gt;&lt;P&gt;1) find the average monthly headcount for each office / site ( 2nd table from the left on snippet)&lt;/P&gt;&lt;P&gt;2) sum the office/site averages to get headcount per group (3rd&amp;nbsp;table from the left on snippet)&lt;/P&gt;&lt;P&gt;3) sum the group values to get total headcount (4th table from the left on snippet)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset covers a number of months but I am using a relative date filter on the visual of 'in the last 1 calendar month' to filter down. The data set contains dates rather than month/year. month/year was in an attempt to simplify the example data&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have got as far as step 2 above using DAX formula&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;All Headcount by Group = SUMX(SUMMARIZE('All Headcount','All Headcount'[Full Name],"Average",AVERAGE('All Headcount'[Headcount])),[Average]&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;and adding this to a table visual alongside 'Group'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;As expected the total of 1,427.19, 'provided' by the table is wrong so I tried to using the formula as a variable in a calculation using 'HASONEVALUE'&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;Test Sum Headcount Averages = &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;VAR HeadcountGroup = SUMX(SUMMARIZE('All Headcount','All Headcount'[Full Name],"Average",AVERAGE('All Headcount'[Headcount])),[Average])&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;IF(HASONEVALUE('All Headcount'[Group]),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;HeadcountGroup,&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;SUMX(VALUES(Headcount[Full Name]),HeadcountGroup))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;However, this has given a total of 18,553.44 which is also wrong. The actual total is 1,680 (to 2 decimal points).&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;Can anyone help, where am I going wrong?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;Relative newbie to DAX so very much learning as I go along&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&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;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 11:43:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674605#M34269</guid>
      <dc:creator>Hanshans</dc:creator>
      <dc:date>2021-02-18T11:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Average Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674675#M34273</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest an AverageX for the inner average.&lt;/P&gt;
&lt;P&gt;Kind regards, Steve.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 12:11:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674675#M34273</guid>
      <dc:creator>stevedep</dc:creator>
      <dc:date>2021-02-18T12:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Average Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674818#M34281</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="232417" data-lia-user-login="Hanshans" class="lia-mention lia-mention-user"&gt;Hanshans&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, you should clearly state the inputs. Can you therefore please describe (in the best way possible, maybe paste a picture) the table(s) you work with? We don't want to see 'a simplified view' of your data. We want to see your data. This is the first thing. You say "&lt;SPAN&gt;The data set contains dates rather than month/year." So, please show us the real thing, not some kind of simplification. If someone writes code that&amp;nbsp; works with a 'simplification,' then the code may not work with the real thing. It'll be a waste of everybody's time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Also, it's always good to state: the input, the transformation and the output. Best in the form of pictures as for the input and output. The explanation of transformation should be easily derived (by the reader) from the pictures but you can add your own words if you feel it's not clear enough.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You do the above and I'll try to figure something out with the info I already have.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 13:33:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1674818#M34281</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-18T13:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sum of Average Sum</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1675054#M34300</link>
      <description>&lt;P&gt;Here's your code:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;AVG = 
var LocationInScope = ISINSCOPE( T[Location] )
var GroupInScope = ISINSCOPE( T[Group] )
var MonthInScope = ISINSCOPE( T[Month] )
var Result =
    SWITCH( TRUE(),
        MonthInScope &amp;amp;&amp;amp; GroupInScope &amp;amp;&amp;amp; LocationInScope, AVERAGE( T[Headcount] ),
        MonthInScope &amp;amp;&amp;amp; GroupInScope &amp;amp;&amp;amp; not LocationInScope,
            AVERAGEX(
                DISTINCT( T[Location] ),
                CALCULATE( AVERAGE( T[Headcount] ) )
            ),
        MonthInScope &amp;amp;&amp;amp; not GroupInScope &amp;amp;&amp;amp; not LocationInScope,
            AVERAGEX(
                DISTINCT( T[Group] ),
                CALCULATE(
                    AVERAGEX(
                        DISTINCT( T[Location] ),
                        CALCULATE( AVERAGE( T[Headcount] ) )
                    )
                )
            ),
        not ( MonthInScope || GroupInScope || LocationInScope ),
        AVERAGEX(
            DISTINCT( T[Month] ),
                CALCULATE(
                AVERAGEX(
                    DISTINCT( T[Group] ),
                    CALCULATE(
                        AVERAGEX(
                            DISTINCT( T[Location] ),
                            CALCULATE( AVERAGE( T[Headcount] ) )
                        )
                    )
                )
            )
        )
    )
return
    Result&lt;/LI-CODE&gt;&lt;P&gt;T[Location] is your T[Office/Site].&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 15:21:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-of-Average-Sum/m-p/1675054#M34300</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-02-18T15:21:14Z</dc:date>
    </item>
  </channel>
</rss>

