<?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: Using Dax calculate the difference between two values comparing two dates in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2906831#M94861</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="464945" data-lia-user-login="unkCandyd" class="lia-mention lia-mention-user"&gt;unkCandyd&lt;/a&gt;&amp;nbsp;Try:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Target Value Measure = 
  VAR __ActualDate = MAX('Actuals'[Actual date])
  VAR __Targets = 
    ADDCOLUMNS(
      'Targets',
      "__DaysAway",ABS( ([target date] - __ActualDate) * 1.)
    )
  VAR __Min = MINX(__Targets,[__DaysAway])
  VAR __Result = MINX(FILTER(__Targets, [__DaysAway] = __Min),[target value])
RETURN
  __Result&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 15 Nov 2022 14:40:33 GMT</pubDate>
    <dc:creator>Greg_Deckler</dc:creator>
    <dc:date>2022-11-15T14:40:33Z</dc:date>
    <item>
      <title>Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2906652#M94847</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Iam beginner in power bi I would like your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first one presents the actual values:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;the second one is the target values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;I want to calculate actual- target values as the target can be retreived from the target table according to actual date. For example:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For id=1, first row I have the date 31-Jan so I should the target value of the date 31-march&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My result will look like as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to implement it in dax but i dont know how to retrieve the target value according to actual date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me to do that,&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:49:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2906652#M94847</guid>
      <dc:creator>unkCandyd</dc:creator>
      <dc:date>2022-11-16T09:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2906831#M94861</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="464945" data-lia-user-login="unkCandyd" class="lia-mention lia-mention-user"&gt;unkCandyd&lt;/a&gt;&amp;nbsp;Try:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Target Value Measure = 
  VAR __ActualDate = MAX('Actuals'[Actual date])
  VAR __Targets = 
    ADDCOLUMNS(
      'Targets',
      "__DaysAway",ABS( ([target date] - __ActualDate) * 1.)
    )
  VAR __Min = MINX(__Targets,[__DaysAway])
  VAR __Result = MINX(FILTER(__Targets, [__DaysAway] = __Min),[target value])
RETURN
  __Result&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 14:40:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2906831#M94861</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2022-11-15T14:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908778#M94993</link>
      <description>&lt;P&gt;Hello, Thank you for reply. bu I dont want to compare the days away, as it may give the wrong target value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have the target dates are 6-June with a target value 100 and 31-Dec with target value 200,&lt;/LI&gt;&lt;LI&gt;and the actual date is 31-Aug, so the target value for this date is 200. but using the suggested calculation it will give me 100. as it is comparing the days away&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Again, I may have explained wrongly, what I want to be able to compare the two dates, so if the actual date &amp;lt;= target date then var = actual value- target value, also to compare all dates.&amp;nbsp;&lt;BR /&gt;I have succeeded to implement it in excel by using the match formula. but using Dax I am blocked..&lt;/P&gt;&lt;P&gt;Thank you again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 08:52:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908778#M94993</guid>
      <dc:creator>unkCandyd</dc:creator>
      <dc:date>2022-11-16T08:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908814#M94995</link>
      <description>&lt;P&gt;Hi unkCandyd,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this method:&lt;/P&gt;
&lt;P&gt;New a measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DateDiff =
CALCULATE (
    DATEDIFF ( MIN ( 'Targets'[target date] ), MAX ( 'Targets'[target date] ), DAY ),
    FILTER ( 'Targets', 'Targets'[id] )
)
&lt;/LI-CODE&gt;
&lt;P&gt;Then new some columns:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MidDate =
CALCULATE (
    MIN ( 'Targets'[target date] ) + [DateDiff] / 2,
    FILTER ( 'Targets', 'actual'[Id] = 'Targets'[id] )
)
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;NeedDate =
IF (
    'actual'[MidDate] &amp;gt; [Actual date],
    CALCULATE (
        MIN ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 'actual'[Id] )
    ),
    CALCULATE (
        MAX ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 'actual'[Id] )
    )
)
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Target Value =
CALCULATE (
    SUM ( Targets[target value] ),
    FILTER ( 'Targets', 'Targets'[target date] = 'actual'[NeedDate] )
)
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Variance = [Actual value] - [Target Value]&lt;/LI-CODE&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps you. Here is my PBIX file.&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 _Yinliw&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:05:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908814#M94995</guid>
      <dc:creator>v-yinliw-msft</dc:creator>
      <dc:date>2022-11-16T09:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908918#M95002</link>
      <description>&lt;P&gt;Hello thanks for your reply, here for the date of 18-May, the target value should be 100 as the date has already passed the 31 March:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Maybe I explained wrongly so after the date is passed we should get the new target of the next date&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:31:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908918#M95002</guid>
      <dc:creator>unkCandyd</dc:creator>
      <dc:date>2022-11-16T09:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908949#M95006</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="464945" data-lia-user-login="unkCandyd" class="lia-mention lia-mention-user"&gt;unkCandyd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Understood.&lt;/P&gt;
&lt;P&gt;But i am a little confused, the 9/30/2022 and 12/15/2022 are both passed the 8/30/2022, and it used the target 8/30. Could you please explain the logic more to me?&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 _Yinliw&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:39:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908949#M95006</guid>
      <dc:creator>v-yinliw-msft</dc:creator>
      <dc:date>2022-11-16T09:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908982#M95007</link>
      <description>&lt;P&gt;Hello, Thank you for your reply. let me explain it more clearly.&lt;/P&gt;&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have the target dates are 6-June with a target value of 100 and 31-Dec with a target value of 200,&lt;/LI&gt;&lt;LI&gt;and the actual date is 31-Aug, so the target date corresponding is 31-Dec.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So getting the target value according to the actual date and target date comparison&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, I may have explained wrongly,&lt;BR /&gt;I have succeeded to implement it in excel by using the match formula. but using Dax I am blocked..&lt;/P&gt;&lt;P&gt;Thank you again&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:44:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2908982#M95007</guid>
      <dc:creator>unkCandyd</dc:creator>
      <dc:date>2022-11-16T09:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2909024#M95009</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="464945" data-lia-user-login="unkCandyd" class="lia-mention lia-mention-user"&gt;unkCandyd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please fix this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the column NeedDate like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NeedDate =
IF (
    'actual'[MidDate] &amp;gt; [Actual date]
        &amp;amp;&amp;amp; 'actual'[Actual date] &amp;lt; MIN ( 'Targets'[target date] ),
    CALCULATE (
        MIN ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 'actual'[Id] )
    ),
    CALCULATE (
        MAX ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 'actual'[Id] )
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result is:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Hope this helps you. Here is my PBIX file.&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 _Yinliw&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 09:57:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2909024#M95009</guid>
      <dc:creator>v-yinliw-msft</dc:creator>
      <dc:date>2022-11-16T09:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2909139#M95013</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="437717" data-lia-user-login="v-yinliw-msft" class="lia-mention lia-mention-user"&gt;v-yinliw-msft&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry to bother you but i tried to implement the calculations. but i got one value that isnt correct.&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example, here i should get the value of 30 June as the value date of April is before the 30-June.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Here the pbix: &lt;A href="https://drive.google.com/file/d/10c9yBPxfNfUpWG-UisERDaI67WAOIixm/view?usp=sharing" target="_blank"&gt;https://drive.google.com/file/d/10c9yBPxfNfUpWG-UisERDaI67WAOIixm/view?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 10:33:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2909139#M95013</guid>
      <dc:creator>unkCandyd</dc:creator>
      <dc:date>2022-11-16T10:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Dax calculate the difference between two values comparing two dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2912204#M95187</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="464945" data-lia-user-login="unkCandyd" class="lia-mention lia-mention-user"&gt;unkCandyd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this method:&lt;/P&gt;
&lt;P&gt;New two columns:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Time =
VAR _min1 =
    CALCULATE (
        MIN ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 1 )
    )
VAR _min3 =
    CALCULATE (
        MIN ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 3 )
    )
VAR _max1 =
    CALCULATE (
        MAX ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 1 )
    )
VAR _max3 =
    CALCULATE (
        MAX ( 'Targets'[target date] ),
        FILTER ( 'Targets', 'Targets'[id] = 3 )
    )
RETURN
    SWITCH (
        TRUE (),
        'actual'[Actual date] &amp;gt; _min1
            &amp;amp;&amp;amp; 'actual'[Actual date] &amp;lt;= _max1
            &amp;amp;&amp;amp; 'actual'[Id] = 1, _max1,
        'actual'[Actual date] &amp;lt;= _min1
            &amp;amp;&amp;amp; 'actual'[Id] = 1, _min1,
        'actual'[Actual date] &amp;gt; _min3
            &amp;amp;&amp;amp; 'actual'[Actual date] &amp;lt;= _max3
            &amp;amp;&amp;amp; 'actual'[Id] = 3, _max3,
        'actual'[Actual date] &amp;lt;= _min3
            &amp;amp;&amp;amp; 'actual'[Id] = 3, _min3
    )
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Target Value = CALCULATE(MAX(Targets[target value]), FILTER('Targets', 'Targets'[target date] = 'actual'[Time] &amp;amp;&amp;amp; 'actual'[Id] = 'Targets'[id]))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps you. Here is my PBIX file.&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 _Yinliw&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&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;</description>
      <pubDate>Thu, 17 Nov 2022 09:49:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-Dax-calculate-the-difference-between-two-values-comparing/m-p/2912204#M95187</guid>
      <dc:creator>v-yinliw-msft</dc:creator>
      <dc:date>2022-11-17T09:49:32Z</dc:date>
    </item>
  </channel>
</rss>

