<?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 compare sum of sales for this period of this month vs the same period of the previous month in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2851200#M91407</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my report, I calculated a comparison measure of the sales of a month compared to the previous month.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Variation = 
	VAR __PREV_MONTH =
		CALCULATE(
			SUM('Table 1'[Sales]),
			DATEADD('Table 1'[Date].[Date], -1, MONTH)
		)
	RETURN
		DIVIDE(SUM('Table 1'[Sales]) - __PREV_MONTH, __PREV_MONTH)
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The concern is that if we are in the current month, the result is not correct since it is a comparison of a non-complete month compared to a complete month.&lt;BR /&gt;In this case, how to do if we are in the current month, to compare the elapsed days of the current month compared to the same period of the previous month.&lt;BR /&gt;(Example: today is 10/19/2022, I am comparing sales from 10/01/2022 to 10/19/2022 vs sales from 09/01/2022 to 09/19/2022)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 11:29:53 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-10-19T11:29:53Z</dc:date>
    <item>
      <title>compare sum of sales for this period of this month vs the same period of the previous month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2851200#M91407</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my report, I calculated a comparison measure of the sales of a month compared to the previous month.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Variation = 
	VAR __PREV_MONTH =
		CALCULATE(
			SUM('Table 1'[Sales]),
			DATEADD('Table 1'[Date].[Date], -1, MONTH)
		)
	RETURN
		DIVIDE(SUM('Table 1'[Sales]) - __PREV_MONTH, __PREV_MONTH)
)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;The concern is that if we are in the current month, the result is not correct since it is a comparison of a non-complete month compared to a complete month.&lt;BR /&gt;In this case, how to do if we are in the current month, to compare the elapsed days of the current month compared to the same period of the previous month.&lt;BR /&gt;(Example: today is 10/19/2022, I am comparing sales from 10/01/2022 to 10/19/2022 vs sales from 09/01/2022 to 09/19/2022)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 11:29:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2851200#M91407</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-19T11:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: compare sum of sales for this period of this month vs the same period of the previous month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2852209#M91497</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;// First and foremost, you should create base measures
// from which all else will follow. So, for instance:

[Total Sales] = SUM('YourFactTable'[Sales] )

// Second, please give your tables decent, pronounceable
// and descriptive (as well as short) names. A name like
// 'Table 1' is not something you'd like the consumers
// of your model to see. It's not informative in the slightest.

// Third, you should always build a proper model with
// dimensions and fact tables. No auto-generated hierarchies
// please as these will be returning wrong results before
// you even know it.

[Variation] =
var ThisMonthSales =
    [Total Sales]
var LastDateWithSales =
    CALCULATE(
        MAX( YourFactTable[Date] ),
        REMOVEFILTERS( )
    )
var PrevMonthAdjusted = 
    DATEADD(
        CALCULATETABLE(
            VALUES( 'Calendar'[Date] ),
            'Calendar'[Date] &amp;lt;= LastDateWithSales,
            VALUES( 'Calendar'[Date] ),
            REMOVEFILTERS( 'Calendar' )
        )
        -1,
        MONTH
    )
VAR PrevMonthSales =
    CALCULATE(
        [Total Sales],
        PrevMonthAdjusted,
        // This last line is not needed if 'Calendar'
        // is marked in the model as a Date Table.
        REMOVEFILTERS( 'Calendar' )
    )
var Output =
    DIVIDE( 
        ThisMonthSales - PrevMonthSales, 
        PrevMonthSales
    )
return
    Output&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to learn about building correct and fast models and why it's of crucial importance to build a star-schema model, you can read &lt;A href="https://www.bing.com/ck/a?!&amp;amp;&amp;amp;p=b8b9df1cedb6a09dJmltdHM9MTY2NjEzNzYwMCZpZ3VpZD0xNzI4ODlkNS01MDAyLTZhNjYtMTE1ZC05YmViNTQwMjZjZjImaW5zaWQ9NTE4OA&amp;amp;ptn=3&amp;amp;hsh=3&amp;amp;fclid=172889d5-5002-6a66-115d-9beb54026cf2&amp;amp;psq=star+schema+in+power+bi&amp;amp;u=a1aHR0cHM6Ly9sZWFybi5taWNyb3NvZnQuY29tL2VuLXVzL3Bvd2VyLWJpL2d1aWRhbmNlL3N0YXItc2NoZW1h&amp;amp;ntb=1" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;THIS&lt;/STRONG&gt;&lt;/A&gt;. Do not fall into the traps that so many have before you.&lt;/P&gt;
&lt;P&gt;You need something like this:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 23:48:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2852209#M91497</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-10-19T23:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: compare sum of sales for this period of this month vs the same period of the previous month</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2853803#M91622</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="349489" data-lia-user-login="daXtreme" class="lia-mention lia-mention-user"&gt;daXtreme&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realy appreciated the way you answered me. You were not content only to give me an answer to my question but also to give me advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2022 13:40:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/compare-sum-of-sales-for-this-period-of-this-month-vs-the-same/m-p/2853803#M91622</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-10-20T13:40:07Z</dc:date>
    </item>
  </channel>
</rss>

