<?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: DATEDIFF incorrect - not sure why in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160483#M113477</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked simply with replacing the FORMAT line as per your suggestion, and just use:&lt;/P&gt;&lt;P&gt;RETURN&lt;/P&gt;&lt;P&gt;_targetdate&lt;/P&gt;&lt;P&gt;It is really strange - I had put this in originally because I could not select the Format of the measure as a date at the time. but it now gives me the option to Format as a date now that I've removed the FORMAT line.&amp;nbsp;&lt;BR /&gt;Anyway, many thanks for your help! The format change now provides the correct calculations:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2023 09:50:22 GMT</pubDate>
    <dc:creator>julesdude</dc:creator>
    <dc:date>2023-03-29T09:50:22Z</dc:date>
    <item>
      <title>DATEDIFF incorrect - not sure why</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160336#M113469</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have the following matrix table in my report:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The Unexpired Lease in Days column contains the following:&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;Unexpired Lease in Days =
VAR _asofdate = [As Of Date]
VAR _leaseenddate = [End Lease Date]
RETURN
DATEDIFF(_asofdate, _leaseenddate, DAY)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, while this provides the correct result in some instances, in others it does not. For example, the date difference between the as of date column and End Lease Date column in the above top row is giving me 6948. When I run these dates in a quick DATEDIF formula in Excel it is giving me a higher figure of 7153&lt;/P&gt;&lt;P&gt;What is the issue here? Surely it should be a simple case of referring to the measure that is creating the value for [End Lease Date], and the same with {As Of Date] and then that works for each row.&lt;/P&gt;&lt;P&gt;[as of date] is the selection of a date from a date picker filter in the report&lt;/P&gt;&lt;P&gt;[End Lease Date] is a more extensive measure that returns a date based on certain criteria, the last line being:&lt;/P&gt;&lt;P&gt;RETURN&lt;/P&gt;&lt;P&gt;FORMAT(_targetdate, "dd/mm/yyyy")&lt;/P&gt;&lt;P&gt;This shouldn't be a problem as the measure calculating the date diff above should simply lift this measure providing the date, and use this in its arguments along with the as of date measure also lifted.&lt;/P&gt;&lt;P&gt;Where am I going wrong?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 08:56:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160336#M113469</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-29T08:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF incorrect - not sure why</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160383#M113473</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="399757" data-lia-user-login="julesdude" class="lia-mention lia-mention-user"&gt;julesdude&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Make sure [End Lease Date] is datetime data type not text. Look like it is aligned left as and indication&amp;nbsp;of a text (dates and numbers are usually aligned right)&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 09:17:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160383#M113473</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-29T09:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF incorrect - not sure why</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160441#M113475</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. Yes I think you are right and this is the issue. However when I select the measure [End Lease Date] so that I can change the Format dropdown on the Ribbon to Date, I only have Text as an option and cannot change this.&lt;BR /&gt;How can I do so? The measure in full is:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;End Lease Date = 
VAR _asOfDate = [As Of Date]
VAR _assetref = [asset reference]
VAR _leaseref = [Lease Reference]
VAR _unitref = MAX(Unit[Unit Reference])
VAR _tenantref = [Tenant Reference]
VAR _datein3months = EDATE([As Of Date],3)
RETURN
VAR _filter = 
FILTER(Lease_Unit,
     MAX(Lease_Unit[Lease.Tenant Reference]) = _tenantref &amp;amp;&amp;amp;
        AND (
            Lease_Unit[Lease.Expiration Date] &amp;gt;= _asOfDate,
            Lease_Unit[Lease.Commencement Date] &amp;lt;= _asOfDate
        )
            || Lease_Unit[Lease.Lease Status] IN { "Holding Over", "Month-to-Month" }
        &amp;amp;&amp;amp; OR( 
            Lease_Unit[Lease.Termination Date] &amp;gt;= _asOfDate, 
        isblank(Lease_Unit[Lease.Termination Date])
        )
     )
VAR _terminationDate = CALCULATE(MAX(Lease_Unit[Lease.Termination Date]),_filter)
VAR _expirationdate = CALCULATE(MAX(Lease_Unit[Lease.Expiration Date]),_filter)
VAR _status = CALCULATE(MAX(Lease_Unit[Lease.Lease Status]),_filter)

VAR _targetdate = IF(NOT ISBLANK(_terminationDate), _terminationDate,  
                    IF(_status = "Holding Over" || _status = "Month-to-Month", _datein3months,
                    IF(NOT ISBLANK(_expirationdate), _expirationdate, 
                    _datein3months))) 

RETURN

FORMAT(_targetdate, "dd/mm/yyyy")&lt;/LI-CODE&gt;&lt;P&gt;I had to put the FORMAT part at the end as it wasn't recognising anything as a date?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 09:34:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160441#M113475</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-29T09:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF incorrect - not sure why</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160463#M113476</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="399757" data-lia-user-login="julesdude" class="lia-mention lia-mention-user"&gt;julesdude&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure the reason for using the FORMAT function. However, please try&lt;/P&gt;
&lt;P&gt;RETURN&lt;BR /&gt;_targetdate&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Or&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;RETURN&lt;BR /&gt;DATEVALUE(FORMAT(_targetdate, "dd/mm/yyyy"))&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 09:41:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160463#M113476</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-29T09:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: DATEDIFF incorrect - not sure why</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160483#M113477</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked simply with replacing the FORMAT line as per your suggestion, and just use:&lt;/P&gt;&lt;P&gt;RETURN&lt;/P&gt;&lt;P&gt;_targetdate&lt;/P&gt;&lt;P&gt;It is really strange - I had put this in originally because I could not select the Format of the measure as a date at the time. but it now gives me the option to Format as a date now that I've removed the FORMAT line.&amp;nbsp;&lt;BR /&gt;Anyway, many thanks for your help! The format change now provides the correct calculations:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 09:50:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DATEDIFF-incorrect-not-sure-why/m-p/3160483#M113477</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-29T09:50:22Z</dc:date>
    </item>
  </channel>
</rss>

