<?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: Use Datediff function in two tables, which located in unrelatet tables in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4273898#M169554</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;You can calculate the dates you want to compare in variables and then place them in datediff.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;e.g. Here I have a custom condition that date2 needs to be in year 2023, date1 has no conditions:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;DDiff no relation =&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;_date1&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;GantDemo&lt;/SPAN&gt;&lt;SPAN&gt;[E_date]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;_date2&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&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'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;YEAR&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;)=&lt;/SPAN&gt;&lt;SPAN&gt;2023&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;datediff&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;_date1&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;_date2&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;DAY&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
The tables are not related. You can add whatever conditions you need in the variable calculations (e.g. id needs to be some specific id).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P&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;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Thu, 07 Nov 2024 10:56:51 GMT</pubDate>
    <dc:creator>ValtteriN</dc:creator>
    <dc:date>2024-11-07T10:56:51Z</dc:date>
    <item>
      <title>Use Datediff function in two tables, which located in unrelatet tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4273774#M169547</link>
      <description>&lt;P&gt;Hello Profis,&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need your help to create a measure to subtract two dates in days, which located in tabels no realtet between them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find the screen shot maybe help you to solve my issue. In addtion i want to create this measure in Fact_SalesOrderLine as you see in the Pic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please if you need more&amp;nbsp; infos, don't hesitate to contect me.&lt;/P&gt;&lt;P&gt;Thanks in Advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 09:47:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4273774#M169547</guid>
      <dc:creator>Talal141218</dc:creator>
      <dc:date>2024-11-07T09:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use Datediff function in two tables, which located in unrelatet tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4273898#M169554</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;You can calculate the dates you want to compare in variables and then place them in datediff.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;e.g. Here I have a custom condition that date2 needs to be in year 2023, date1 has no conditions:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;DDiff no relation =&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;_date1&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;S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conditions you need in the variable calculations (e.g. id needs to be some specific id).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P&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;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 07 Nov 2024 10:56:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4273898#M169554</guid>
      <dc:creator>ValtteriN</dc:creator>
      <dc:date>2024-11-07T10:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Use Datediff function in two tables, which located in unrelatet tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4274160#M169564</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstful thanks alot for your response,and i have results now but those are neither corresponding nor logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 13:54:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4274160#M169564</guid>
      <dc:creator>Talal141218</dc:creator>
      <dc:date>2024-11-07T13:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use Datediff function in two tables, which located in unrelatet tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4274824#M169596</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="420267" data-lia-user-login="Talal141218" class="lia-mention lia-mention-user"&gt;Talal141218&lt;/a&gt; ,&lt;BR /&gt;According to your description, after you arrive at the results, there may be data mismatches in the results, or the calculated values do not make logical sense, I try to reproduce your problem with some sample data, I hope to provide some ideas for the problems you encountered!&lt;BR /&gt;My sample data is calculating the difference between the date of each sales order and the date of the latest purchase order, and in the case where I am using the error code , although the value is returned, there is a logic error, as detailed below:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Order corresponds to multiple Purch values, and since we don't have a relationship, we need the other columns to help us make sure that there are no duplicate values, and we can get the correct value.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DateDiffMeasure = 
VAR OrderDate = MAX(Sales[OrderDate])
VAR ClosestPurchaseDate = 
    CALCULATE(
        MIN(Purch[PurchaseDate]),
        FILTER(
            Purch,
            Purch[PurchaseDate] &amp;lt;= OrderDate // Ensure that the purchase date is before the order date
                &amp;amp;&amp;amp; Purch[Index] =MAX('Sales'[OrderID]) // Ensure that each order is uniquely matched
        ),
        TOPN(1, Purch, Purch[PurchaseDate], DESC) // Get the most recent PurchaseDate
    )
RETURN
IF(
    NOT(ISBLANK(ClosestPurchaseDate)),
    ABS(DATEDIFF(OrderDate, ClosestPurchaseDate, DAY)),
    BLANK()
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If you still have questions you can check out my pbix, I hope my answer can further answer your questions and I would be honored if I can solve your problem!&lt;/P&gt;
&lt;P&gt;Hope it helps!&lt;/P&gt;
&lt;P&gt;Best regards,&lt;BR /&gt;Community Support Team_ Tom Shen&lt;/P&gt;
&lt;P&gt;If this post helps then please consider&amp;nbsp;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 02:17:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-Datediff-function-in-two-tables-which-located-in-unrelatet/m-p/4274824#M169596</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-08T02:17:20Z</dc:date>
    </item>
  </channel>
</rss>

