<?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: Create Dynamic Previous Result in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Previous-Result/m-p/3213271#M117250</link>
    <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="434309" data-lia-user-login="eliasayyy" class="lia-mention lia-mention-user"&gt;eliasayyy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you are using the&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;timeline slicer custom visual . And your dimension is Year,Month and week . And you want to select one and then get the comparsion of the current object and previous object.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here are the steps you can refer to :&lt;BR /&gt;(1)This is my test data:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;For your need ,i recommend the 'Calendar' Table contains the all year's date.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Calendar = &lt;/SPAN&gt;&lt;SPAN&gt;CALENDAR&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;2014&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;2016&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;12&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;31&lt;/SPAN&gt;&lt;SPAN&gt;) )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;(2)Then we can create a measure like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
 var _slicer = MAX('Calendar'[Date])
var _cur_year =  YEAR(_slicer)
var _pre_year  = _cur_year -1 
var _diff_year =SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date]) = _pre_year)
var _curmonth = EOMONTH(_slicer ,-2)+1
var _diff_month = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ MONTH('Calendar'[Date]) = YEAR(_curmonth)*100+ MONTH(_curmonth)      )
var _preweek = YEAR( _slicer-7)*100 + WEEKNUM(_slicer-7)
var _diff_week = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ WEEKNUM('Calendar'[Date]) = _preweek      )
var _count = COUNTROWS('Calendar')
 return
IF(_count&amp;gt;300 , _diff_year , IF(_count&amp;gt;27 , _diff_month , _diff_week))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;(3)Then we can put this measure on the card visual and we can get the comparsion.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Aniya Zhang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt; it as the solution&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2023 06:01:15 GMT</pubDate>
    <dc:creator>v-yueyunzh-msft</dc:creator>
    <dc:date>2023-05-01T06:01:15Z</dc:date>
    <item>
      <title>Create Dynamic Previous Result</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Previous-Result/m-p/3210696#M117082</link>
      <description>&lt;P&gt;hello everyone i am using timeline slicer custom visual with all granuality on from by day to by year.&lt;BR /&gt;&lt;BR /&gt;i want to make a measure that will compare current vs previous based on selected date&lt;BR /&gt;&lt;BR /&gt;so if i i am on the "By year" slicer , if i select 2023, i want to compare 2023 result to 2022 result ,&lt;BR /&gt;if i am on "By week" slicer , if i select week 3 of 2023 i want to compare to week 2 of 2023&lt;BR /&gt;if i am on "By month" slicer , if i select january 2023 i want to compare to december 2023&lt;BR /&gt;&lt;BR /&gt;is this possible?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 07:14:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Previous-Result/m-p/3210696#M117082</guid>
      <dc:creator>eliasayyy</dc:creator>
      <dc:date>2023-04-28T07:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dynamic Previous Result</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Previous-Result/m-p/3213271#M117250</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="434309" data-lia-user-login="eliasayyy" class="lia-mention lia-mention-user"&gt;eliasayyy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you are using the&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;timeline slicer custom visual . And your dimension is Year,Month and week . And you want to select one and then get the comparsion of the current object and previous object.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Here are the steps you can refer to :&lt;BR /&gt;(1)This is my test data:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;For your need ,i recommend the 'Calendar' Table contains the all year's date.&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Calendar = &lt;/SPAN&gt;&lt;SPAN&gt;CALENDAR&lt;/SPAN&gt;&lt;SPAN&gt;( &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;2014&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;DATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;2016&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;12&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;31&lt;/SPAN&gt;&lt;SPAN&gt;) )&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;(2)Then we can create a measure like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
 var _slicer = MAX('Calendar'[Date])
var _cur_year =  YEAR(_slicer)
var _pre_year  = _cur_year -1 
var _diff_year =SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date]) = _pre_year)
var _curmonth = EOMONTH(_slicer ,-2)+1
var _diff_month = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ MONTH('Calendar'[Date]) = YEAR(_curmonth)*100+ MONTH(_curmonth)      )
var _preweek = YEAR( _slicer-7)*100 + WEEKNUM(_slicer-7)
var _diff_week = SUM('Sales'[Sales])- CALCULATE( SUM('Sales'[Sales]) , YEAR('Calendar'[Date])*100+ WEEKNUM('Calendar'[Date]) = _preweek      )
var _count = COUNTROWS('Calendar')
 return
IF(_count&amp;gt;300 , _diff_year , IF(_count&amp;gt;27 , _diff_month , _diff_week))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;(3)Then we can put this measure on the card visual and we can get the comparsion.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Aniya Zhang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt; it as the solution&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 06:01:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Create-Dynamic-Previous-Result/m-p/3213271#M117250</guid>
      <dc:creator>v-yueyunzh-msft</dc:creator>
      <dc:date>2023-05-01T06:01:15Z</dc:date>
    </item>
  </channel>
</rss>

