<?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: Estimated total sales based on the mean in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3057065#M105495</link>
    <description>&lt;P&gt;Hello&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;thank you so much! I made a mistake when transferring your measures into my file:&lt;/P&gt;&lt;P&gt;I inserted my measure [Estimated total sales] into the COALESCE fuction instead of the variable&amp;nbsp;&lt;SPAN&gt;EstimatedTotalSales!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you again and have a good day!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Greetings&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2023 07:02:09 GMT</pubDate>
    <dc:creator>Jan_Trummel</dc:creator>
    <dc:date>2023-02-02T07:02:09Z</dc:date>
    <item>
      <title>Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3053251#M105240</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;I have a longer question. I will try to describe the whole thing as clearly as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H1&gt;1) This is my data&lt;/H1&gt;&lt;P&gt;I use the database &lt;EM&gt;ContosoRetailDW_2019&lt;/EM&gt;. From this I imported the following 2 tables:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Fact Sales&lt;/LI&gt;&lt;LI&gt;DimDate&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Of course, both tables are linked via a 1-to-N relationship.&lt;/P&gt;&lt;P&gt;I only imported sales before 8/1/2009. If I have the total sales per year and month displayed in a matrix, this is the picture I get:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H1&gt;2) This what I want to do&lt;/H1&gt;&lt;P&gt;I would now like to estimate the total sales for the months of August to December 2009, using the mean value of the total sales for the past few months. This is a bit difficult to describe, so I'll show you what I want to do in Excel:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H1&gt;3) These are my measures&lt;/H1&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;3.1) The measure &lt;EM&gt;Total Sales&lt;/EM&gt;&lt;/H2&gt;&lt;P&gt;I start by creating the &lt;STRONG&gt;&lt;EM&gt;Total Sales&lt;/EM&gt;&lt;/STRONG&gt; measure:&lt;/P&gt;&lt;PRE&gt;Total Sales = SUM(FactSales[SalesAmount])&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;3.2) The measure &lt;EM&gt;Total sales one month all years&lt;/EM&gt;&lt;/H2&gt;&lt;P&gt;Now I need a measure that adds up the total sales of a month over all years. I will use it as a dividend in my closing calculation. For a better understanding, I'll show you again in Excel what I want to calculate:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Here is the measure&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Total sales one month all years&lt;/STRONG&gt;&lt;/EM&gt;:&lt;/P&gt;&lt;PRE&gt;Total sales one month all years =&lt;BR /&gt;&lt;BR /&gt;CALCULATE(&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; [Total Sales],&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ALL(DimDate[CalendarYear])&lt;BR /&gt;&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;When I drag the measure into the matrix I get this picture:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;3.3) The measure &lt;EM&gt;Number of total sales one month all years&lt;/EM&gt; (&lt;U&gt;&lt;STRONG&gt;here are the problems!&lt;/STRONG&gt;&lt;/U&gt;)&lt;/H2&gt;&lt;P&gt;Now I need a measure that gives me the number of total sales. So that you know what I mean, I'll show you again in Excel what I want to do:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I wrote the following measure&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Number of total sales one month all years&lt;/EM&gt;&lt;/STRONG&gt;:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;Number of total sales one month all years = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;COUNTX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ADDCOLUMNS&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;SUMMARIZE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(DimDate),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DimDate[CalendarYear],&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DimDate[CalendarMonthLabel]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;"Result"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Total Sales]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; ),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; [Result]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;The idea is this: I create a table grouped by year and month with SUMMARIZE and then add a result column with ADDCOLUMNS, in which I calculate the total sales. I then use COUNTX to count how many results I have in my summary table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;You can see that I get the correct numbers in the values of the matrix. The result column is also correct. However, I cannot explain the values in the result line. Here the total amount (31) comes out everywhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;3.4) The measure &lt;EM&gt;Estimated total sales&lt;/EM&gt;&lt;/H2&gt;&lt;P&gt;Anyway, I'll keep going on. I now create the &lt;EM&gt;&lt;STRONG&gt;Estimated total sales&lt;/STRONG&gt;&lt;/EM&gt; measure:&lt;/P&gt;&lt;PRE&gt;Estimated total sales =&lt;BR /&gt;&lt;BR /&gt;[Total Sales One month All years] / [Number of Total Sales One Month All Years]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;3.5) The measure &lt;EM&gt;Total sales or estimated sales&lt;/EM&gt;&lt;/H2&gt;&lt;P&gt;Now I create the final measure, which outputs either &lt;EM&gt;Total sales&lt;/EM&gt; or &lt;EM&gt;Estimated total sales&lt;/EM&gt;:&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;Total Sales or estimated total sales = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;ISBLANK&lt;/SPAN&gt;&lt;SPAN&gt;([Total Sales]), &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; [Estimated total sales], &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; [Total Sales]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I drag it into the matrix and of course the overall results are wrong:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It should actually look like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H1&gt;4) How are you doing right?&lt;/H1&gt;&lt;P&gt;Thank you so much for reading this really long text!&lt;/P&gt;&lt;P&gt;I am of course aware that the problem lies in the measure &lt;EM&gt;Number of Total Sales One Month All Years&lt;/EM&gt;. Unfortunately I can't find the right solution.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Can you help me?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thanks in advance!&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 31 Jan 2023 16:25:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3053251#M105240</guid>
      <dc:creator>Jan_Trummel</dc:creator>
      <dc:date>2023-01-31T16:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3053819#M105270</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="263333" data-lia-user-login="Jan_Trummel" class="lia-mention lia-mention-user"&gt;Jan_Trummel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the great question, and laying out clearly everything you have tried so far!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My main recommendation is to use AVERAGEX to determine the estimated total sales average across all years.&lt;/P&gt;
&lt;P&gt;Since AVERAGEX automatically excludes blanks, you can avoid writing any DAX to count nonblank values yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how I would write the &lt;STRONG&gt;Total Sales or estimated total sales&lt;/STRONG&gt; measure. I have put all the logic in one measure, but you can certainly split the calculations across measures as you originally did.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Sales or estimated total sales = 
SUMX (
    -- Sum by Year/Month
    SUMMARIZE ( 
        DimDate,
        DimDate[CalendarYear],
        DimDate[CalendarMonthLabel]
    ),
    VAR TotalSales =
        [Total Sales]
    -- Average of Total Sales across all years
    VAR EstimatedTotalSales =
        AVERAGEX (
            ALL ( DimDate[CalendarYear] ),
            [Total Sales] -- blanks automatically excluded from average
        )
    RETURN
	-- Syntax sugar for IF ( ISBLANK ( TotalSales ), EstimatedTotalSales, TotalSales )
    COALESCE (
        TotalSales,
        EstimatedTotalSales
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;Does this give the expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 22:09:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3053819#M105270</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-01-31T22:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3054745#M105332</link>
      <description>&lt;P&gt;Hello&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;thank you so much for your detailed answer!&amp;nbsp;Using AVERAGEX and COALESCE definitely makes things a lot easier!&lt;/P&gt;&lt;P&gt;So your answer definitely helps me. Unfortunately, not everything is as I would like it to be.&amp;nbsp;When I use your measure in the matrix I get this result:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The values in the Totals column are now correct. However, the annual result for 2009 and the overall result for the whole table are still wrong. I have circled the incorrect results in red, the correct results in green.&lt;/P&gt;&lt;P&gt;In the Excel spreadsheet I show you what the correct results should be. You only have to pay attention to the red colored cells:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The reason for the erroneous results must lie in the filter context, which is different for the overall results than for the values in the matrix.&lt;/P&gt;&lt;P&gt;Do you have any idea how I can get the right numbers in the overall results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 09:21:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3054745#M105332</guid>
      <dc:creator>Jan_Trummel</dc:creator>
      <dc:date>2023-02-01T09:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3055100#M105355</link>
      <description>&lt;P&gt;Hi again&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="263333" data-lia-user-login="Jan_Trummel" class="lia-mention lia-mention-user"&gt;Jan_Trummel&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for testing it out.&lt;/P&gt;
&lt;P&gt;That's odd, because in my test PBIX using I believe the same Contoso source data, I do get the correct results.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://ozerconsulting-my.sharepoint.com/:u:/g/personal/owen_owenaugerbi_com/ERl0QfCPehtJsiXIx0MnvvEBtBm4YgWuBJ4L6dBd41N9PQ?e=EU4Ffm" target="_blank" rel="noopener"&gt;Link to my PBIX&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In creating my dataset, I added a column 'Date'[CalendarMonth Number] which I set as a sort-by column for 'Date'[CalendarMonthLabel].&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the results I get, with the right-hand matrix being similar to yours, but with the correct values:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;To be honest, I can't see any obvious reason why those totals could be wrong. Assuming we're using the exact same DAX expression for the measure, it must be a difference in the data model, possibly sort-by columns or relationships?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you compare the data model in my PBIX linked above to yours, and see if there's an obvious difference that might explain the results you're seeing? Or if you can share a link to your PBIX, I can take a look as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2023 12:08:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3055100#M105355</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-02-01T12:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3057065#M105495</link>
      <description>&lt;P&gt;Hello&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;thank you so much! I made a mistake when transferring your measures into my file:&lt;/P&gt;&lt;P&gt;I inserted my measure [Estimated total sales] into the COALESCE fuction instead of the variable&amp;nbsp;&lt;SPAN&gt;EstimatedTotalSales!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you again and have a good day!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Greetings&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 07:02:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3057065#M105495</guid>
      <dc:creator>Jan_Trummel</dc:creator>
      <dc:date>2023-02-02T07:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Estimated total sales based on the mean</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3057709#M105538</link>
      <description>&lt;P&gt;Glad it's working - you're welcome! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 11:48:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Estimated-total-sales-based-on-the-mean/m-p/3057709#M105538</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-02-02T11:48:22Z</dc:date>
    </item>
  </channel>
</rss>

