<?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: Help with DateDiff to calculate a better Year, Month, Day combination in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3224030#M117995</link>
    <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="363971" data-lia-user-login="Adam01" class="lia-mention lia-mention-user"&gt;Adam01&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you seems to want to get the Years ,Month and Days customly.&lt;/P&gt;
&lt;P&gt;This is my test data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can create three calcualted columns like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Year = var _addyear= EOMONTH([Column1],12*DATEDIFF([Column1],[Column2],YEAR))
return
IF(_addyear&amp;gt;[Column2],DATEDIFF([Column1],[Column2],YEAR)-1,DATEDIFF([Column1],[Column2],YEAR))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Month = var _addyear= EOMONTH([Column1],12*[Year]-1)+1
var _month_day =  IF( MONTH([Column1]) &amp;gt; MONTH( [Column2]) , 1, IF(DAY([Column1])&amp;gt;DAY([Column2]) ,1,-1))
return
IF(_month_day=1,DATEDIFF(_addyear,[Column2],MONTH)-1,DATEDIFF(_addyear,[Column2],MONTH))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Days = var _addyear= EOMONTH([Column1],12*[Year]-1)+1
 var _addmonth =DATE( YEAR( EOMONTH(_addyear,[Month]) ) ,MONTH( EOMONTH(_addyear,[Month]) ) , DAY([Column1]))
 return

DATEDIFF(_addmonth,[Column2],DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then we can get the result is as follows:&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this method does not meet your needs, you can provide us with your special &lt;STRONG&gt;sample data&lt;/STRONG&gt; and the &lt;STRONG&gt;desired output sample&lt;/STRONG&gt; data in the form of &lt;STRONG&gt;tables&lt;/STRONG&gt;, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )&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, 08 May 2023 02:47:58 GMT</pubDate>
    <dc:creator>v-yueyunzh-msft</dc:creator>
    <dc:date>2023-05-08T02:47:58Z</dc:date>
    <item>
      <title>Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3222297#M117821</link>
      <description>&lt;P&gt;Afternoon All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have 3 DAX expression that calculates a date difference from a fixed date, 1 for year, 1 for month, 1 for day that is essentially DATEDIFF ( [Fixed Date], TODAY(), YEAR ) but replace YEAR with MONTH and DAY respectively&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I want:&amp;nbsp;"2 Years, 5 months, 18 days"&lt;/P&gt;&lt;P&gt;Here's what I get:&amp;nbsp;"2 years, 29 months, 899 days"&lt;/P&gt;&lt;P&gt;(Please note these values are plucked randomly from the air they might not be the correct conversion)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand why the DAX is returning the numbers I get I am just unsure of how to return the desired value I want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 14:07:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3222297#M117821</guid>
      <dc:creator>Adam01</dc:creator>
      <dc:date>2023-05-05T14:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3222309#M117822</link>
      <description>&lt;P&gt;can you hsare some sample please&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 14:13:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3222309#M117822</guid>
      <dc:creator>eliasayyy</dc:creator>
      <dc:date>2023-05-05T14:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3224030#M117995</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="363971" data-lia-user-login="Adam01" class="lia-mention lia-mention-user"&gt;Adam01&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, you seems to want to get the Years ,Month and Days customly.&lt;/P&gt;
&lt;P&gt;This is my test data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We can create three calcualted columns like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Year = var _addyear= EOMONTH([Column1],12*DATEDIFF([Column1],[Column2],YEAR))
return
IF(_addyear&amp;gt;[Column2],DATEDIFF([Column1],[Column2],YEAR)-1,DATEDIFF([Column1],[Column2],YEAR))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Month = var _addyear= EOMONTH([Column1],12*[Year]-1)+1
var _month_day =  IF( MONTH([Column1]) &amp;gt; MONTH( [Column2]) , 1, IF(DAY([Column1])&amp;gt;DAY([Column2]) ,1,-1))
return
IF(_month_day=1,DATEDIFF(_addyear,[Column2],MONTH)-1,DATEDIFF(_addyear,[Column2],MONTH))&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Days = var _addyear= EOMONTH([Column1],12*[Year]-1)+1
 var _addmonth =DATE( YEAR( EOMONTH(_addyear,[Month]) ) ,MONTH( EOMONTH(_addyear,[Month]) ) , DAY([Column1]))
 return

DATEDIFF(_addmonth,[Column2],DAY)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then we can get the result is as follows:&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this method does not meet your needs, you can provide us with your special &lt;STRONG&gt;sample data&lt;/STRONG&gt; and the &lt;STRONG&gt;desired output sample&lt;/STRONG&gt; data in the form of &lt;STRONG&gt;tables&lt;/STRONG&gt;, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )&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, 08 May 2023 02:47:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3224030#M117995</guid>
      <dc:creator>v-yueyunzh-msft</dc:creator>
      <dc:date>2023-05-08T02:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3228393#M118341</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="433015" data-lia-user-login="v-yueyunzh-msft" class="lia-mention lia-mention-user"&gt;v-yueyunzh-msft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see below for a screenshot of what i'm trying to get from this query:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However using your code I very nearly get my desired output except the month / day overlap:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I'm using:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Year = 
VAR AddYear =
    EOMONTH (
        Dates[Start Date],
        12 * DATEDIFF ( Dates[Start Date], Dates[Today], YEAR )
    )
RETURN
    IF (
        AddYear &amp;gt; Dates[Today],
        DATEDIFF ( Dates[Start Date], Dates[Today], YEAR ) - 1,
        DATEDIFF ( Dates[Start Date], Dates[Today], YEAR )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Month = 
VAR AddYear =
    EOMONTH ( Dates[Start Date], 12 * [Year] - 1 ) + 1
VAR MonthDay =
    IF (
        MONTH ( Dates[Start Date] ) &amp;gt; MONTH ( Dates[Today] ),
        1,
        IF ( DAY ( Dates[Start Date] ) &amp;gt; DAY ( Dates[Today] ), 1, -1 )
    )
RETURN
    IF (
        MonthDay = 1,
        DATEDIFF ( AddYear, Dates[Today], MONTH ) - 1,
        DATEDIFF ( AddYear, Dates[Today], MONTH )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Day = 
VAR AddYear =
    EOMONTH ( Dates[Start Date], 12 * Dates[Year] - 1 ) + 1
VAR AddMonth =
    DATE ( YEAR ( EOMONTH ( AddYear, Dates[Month] ) ), MONTH ( EOMONTH ( AddYear, Dates[Month] ) ), DAY ( Dates[Start Date] ) )
RETURN
    DATEDIFF ( AddMonth, Dates[Today], DAY )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 10 May 2023 08:28:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3228393#M118341</guid>
      <dc:creator>Adam01</dc:creator>
      <dc:date>2023-05-10T08:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3228776#M118387</link>
      <description>&lt;P&gt;Here's one way to do it. Just replace T2 with your actual table name. However, I recommend you do it in a measure instead of a column (so you can do calculations first).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;FromToday =
VAR t =
    TODAY ()
VAR dt = T2[Date]
VAR months =
    DATEDIFF ( dt, t, MONTH )
VAR todaymonthsago =
    EDATE ( t, - months )
VAR yrs =
    INT ( months / 12 )
VAR mnths =
    IF ( dt &amp;lt; todaymonthsago, months - 12 * yrs, months - 12 * yrs - 1 )
VAR dys =
    IF (
        dt &amp;lt; todaymonthsago,
        INT ( todaymonthsago - dt ),
        INT ( EDATE ( dt, 1 ) - todaymonthsago )
    )
RETURN
    yrs &amp;amp; " yrs " &amp;amp; mnths &amp;amp; " mos " &amp;amp; dys &amp;amp; " days"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 12:43:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3228776#M118387</guid>
      <dc:creator>ppm1</dc:creator>
      <dc:date>2023-05-10T12:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with DateDiff to calculate a better Year, Month, Day combination</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3229040#M118420</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="443516" data-lia-user-login="ppm1" class="lia-mention lia-mention-user"&gt;ppm1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That seems to have worked, thank you very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2023 14:42:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Help-with-DateDiff-to-calculate-a-better-Year-Month-Day/m-p/3229040#M118420</guid>
      <dc:creator>Adam01</dc:creator>
      <dc:date>2023-05-10T14:42:44Z</dc:date>
    </item>
  </channel>
</rss>

