<?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: YTD For All Years in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317638#M57791</link>
    <description>&lt;P&gt;&amp;nbsp;If you want to use year slicer this might be for you other wise you need to calculte ytd for all years&lt;BR /&gt;first you need to calculate year start date&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;year start date = STARTOFYEAR(DateTime[DateKey])&lt;/LI-CODE&gt;&lt;P&gt;then you need to create year rank using this logic:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;year rank = RANKX(all('calender table'),'calender table'[year start date],,ASC,Dense)&lt;/LI-CODE&gt;&lt;P&gt;then use this logic to calculate ytd:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Ytd = 
CALCULATE(SUM('sales table'[sales]),FILTER(all(calender table),calender table[year rank]=max(calender table[year rank])-1))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 12:14:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-02-03T12:14:47Z</dc:date>
    <item>
      <title>YTD For All Years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317002#M57752</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got a calendar and a sales table (starting from 2018) and i am looking to get YTD of all years up to the latest date based on selected year month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say the user selects 2022-Feb then it should return YTD Sales for 2018-Feb, 2019-Feb, 2020-Feb, 2021-Feb&amp;nbsp; and 2022-Feb. Same thing as when 2022-Jan is selected YTD Sales for 2018-Jan, 2019-Jan, 2020-Jan, 2021-Jan and 2022-Jan.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the user selects 2020-Mar then it should return 2018-Mar, 2019-Mar&amp;nbsp; 2020-Mar.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any help is highly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 06:47:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317002#M57752</guid>
      <dc:creator>rioshox</dc:creator>
      <dc:date>2022-02-03T06:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: YTD For All Years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317052#M57755</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;For a basic YTD calculation you can use pattern like this: CALCULATE([Your measure],DATESYTD('Calendar'[Date])). Then to get your desired end result you can add to this LY, LY-1, LY-2 and so on. Do you have a set amount of years you want to calculate together (e.g. 4) or all the years for all time? If this is the case we might need a different dax.&lt;BR /&gt;&lt;BR /&gt;This DAX resets every year and adds all the values prior to the max month:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;YTD = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;maxdate&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar example'[Date]&lt;/SPAN&gt;&lt;S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AN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'[Month]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;=&lt;/SPAN&gt;&lt;SPAN&gt;_month&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'[Year]&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;=&lt;/SPAN&gt;&lt;SPAN&gt;_year&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!&lt;BR /&gt;&lt;BR /&gt;My LinkedIn: &lt;A href="https://www.linkedin.com/in/n%C3%A4ttiahov-00001/" target="_blank" rel="noopener"&gt;https://www.linkedin.com/in/n%C3%A4ttiahov-00001/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 07:21:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317052#M57755</guid>
      <dc:creator>ValtteriN</dc:creator>
      <dc:date>2022-02-03T07:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: YTD For All Years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317638#M57791</link>
      <description>&lt;P&gt;&amp;nbsp;If you want to use year slicer this might be for you other wise you need to calculte ytd for all years&lt;BR /&gt;first you need to calculate year start date&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;year start date = STARTOFYEAR(DateTime[DateKey])&lt;/LI-CODE&gt;&lt;P&gt;then you need to create year rank using this logic:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;year rank = RANKX(all('calender table'),'calender table'[year start date],,ASC,Dense)&lt;/LI-CODE&gt;&lt;P&gt;then use this logic to calculate ytd:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Ytd = 
CALCULATE(SUM('sales table'[sales]),FILTER(all(calender table),calender table[year rank]=max(calender table[year rank])-1))&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 12:14:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2317638#M57791</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-02-03T12:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: YTD For All Years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2327844#M58348</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="354739" data-lia-user-login="rioshox" class="lia-mention lia-mention-user"&gt;rioshox&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key to solving the problem is to get the respective period of each year according to the month selected by the slicer. Firstly, you need to have an independent date table, use it as slicer.&lt;/P&gt;
&lt;P&gt;(1) create the Date table&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;(2) create the measure bellow,&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = 
    var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date]))
    var _currentMonth = DATE(YEAR(MIN('Table'[Date])),_selectedMonth,1)
    var _dateStart = EDATE(_currentMonth,-12)
return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[Date] &amp;gt;= _dateStart &amp;amp;&amp;amp; 'Table'[Date] &amp;lt;= _currentMonth))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;as you can see above, if you select 2022-Jan, then _currentMonth = 2022 - Jan,&amp;nbsp;_dateStart = 2021 - Jan, then Measure returns total of this period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;But if&lt;/STRONG&gt; you want to get same period in last years, try this&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure2 = 
    var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date]))
return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth &amp;amp;&amp;amp; YEAR('Table'[Date])= year(MIN('Table'[Date]))))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Besides&lt;/STRONG&gt;, if you want to add total to this visual, try this&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure2-1 = 
    var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date]))
return CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth &amp;amp;&amp;amp; YEAR('Table'[Date])= year(MIN('Table'[Date]))))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Measure2-2 = 
    var _selectedMonth = MONTH(SELECTEDVALUE('Date'[Date]))
return SUMX(FILTER(ALL('Table'),MONTH('Table'[Date])= _selectedMonth),[Measure2-1])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Measure2 = IF(ISINSCOPE('Table'[Date].[Year]),[Measure2-1],[Measure2-2])&lt;/LI-CODE&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;Best Regards,&lt;/P&gt;
&lt;P&gt;Community Support Team _Tang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 06:51:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/YTD-For-All-Years/m-p/2327844#M58348</guid>
      <dc:creator>v-xiaotang</dc:creator>
      <dc:date>2022-03-11T06:51:52Z</dc:date>
    </item>
  </channel>
</rss>

