<?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: Subtract two values based on Rank in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331986#M171984</link>
    <description>&lt;P&gt;Thanks for the replies from&amp;nbsp;mark_endicott.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="899356" data-lia-user-login="Valentin09" class="lia-mention lia-mention-user"&gt;Valentin09&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your description, I created simple data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try the following DAX formula:&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;Difference = 
VAR _count=CALCULATE(COUNT('Table'[Name]),ALLEXCEPT('Table','Table'[Name]))
VAR _current=MAX('Table'[Testrang])
VAR CurrentTestrang=CALCULATE(SUM('Table'[Wert]),FILTER(ALLEXCEPT('Table','Table'[Name]),'Table'[Testrang]=_current))
VAR PreviousTestrang=CALCULATE(SUM('Table'[Wert]),FILTER(ALLEXCEPT('Table','Table'[Name]),'Table'[Testrang]=_current-1))
return
IF(_count&amp;gt;1&amp;amp;&amp;amp;_current&amp;gt;1,CurrentTestrang-PreviousTestrang,blank())&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;Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;I&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/I&gt;, then please consider&amp;nbsp;&lt;I&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/I&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Dec 2024 03:11:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-12-17T03:11:45Z</dc:date>
    <item>
      <title>Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331085#M171921</link>
      <description>&lt;P&gt;I have the following table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I want to subtract the current testscore (Testrang = 1) with the previous testscore (Testrang = 2). In this example I want to have the following calculation: Name: "Aaron" / current score = 50 / previous testscore = 50 --&amp;gt; result: 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Either as a measure or as a new column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope somebody can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Valentin&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 14:44:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331085#M171921</guid>
      <dc:creator>Valentin09</dc:creator>
      <dc:date>2024-12-16T14:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331121#M171924</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="899356" data-lia-user-login="Valentin09" class="lia-mention lia-mention-user"&gt;Valentin09&lt;/a&gt;&amp;nbsp;- See below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR _name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _prev_test =
    SELECTEDVALUE ( 'Table'[Testrang] ) - 1
VAR _prev_test_score =
    CALCULATE (
        SUM ( 'Table'[Wert] ),
        REMOVEFILTERS ( 'Table'[Testrang] ),
        'Table'[Testrang] = _prev_test
            &amp;amp;&amp;amp; 'Table'[Name] = _name
    )
VAR _current_minus_prev =
    SUM ( 'Table'[Wert] ) - _prev_test_score
RETURN
    _current_minus_prev&lt;/LI-CODE&gt;
&lt;P&gt;You'll just need to swap out my table and column names for yours.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this works for you please accept as the solution for visibilty of others.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 14:57:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331121#M171924</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-12-16T14:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331192#M171934</link>
      <description>&lt;P&gt;Thanks a lot for your response, but unfortunately it isn't working as I wished. Here is the formula I have used:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here is the visual with the scores:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:30:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331192#M171934</guid>
      <dc:creator>Valentin09</dc:creator>
      <dc:date>2024-12-16T15:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331227#M171943</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="899356" data-lia-user-login="Valentin09" class="lia-mention lia-mention-user"&gt;Valentin09&lt;/a&gt;&amp;nbsp; - Do you have multiple test types? This was't specified, so it looks like my measure is returning the first result it finds, regardless of test type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In which case use this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR _name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _test_type = 
    SELECTEDVALUE( 'Table'[Test] )
VAR _prev_test =
    SELECTEDVALUE ( 'Table'[Testrang] ) - 1
VAR _prev_test_score =
    CALCULATE (
        SUM ( 'Table'[Wert] ),
        REMOVEFILTERS ( 'Table'[Testrang] ),
        'Table'[Testrang] = _prev_test
            &amp;amp;&amp;amp; 'Table'[Name] = _name
            &amp;amp;&amp;amp; 'Table'[Test] = _test_type
    )
VAR _current_minus_prev =
    SUM ( 'Table'[Wert] ) - _prev_test_score
RETURN
    _current_minus_prev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this works for you please accept as the solution for visibilty of others.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 15:47:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331227#M171943</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-12-16T15:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331270#M171946</link>
      <description>&lt;P&gt;Thanks a lot, but this has no effect on the values. Yes I have different Testtypes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 16:06:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331270#M171946</guid>
      <dc:creator>Valentin09</dc:creator>
      <dc:date>2024-12-16T16:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331285#M171947</link>
      <description>&lt;P&gt;Ok so in that case the visual must already have been filtered to the test type. If you have multiple tests per person, within the same type, how are you filtering it to show the 2 most recent results? If you are not filtering it, and you are using measures to display columns 2 &amp;amp; 3 of your visual, you'll need to factor this into the DAX, I suggest something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR _name =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _test_type = 
    SELECTEDVALUE( 'Table'[Test] )
VAR _recent_test = 
    MAX ( 'Table'[Testrang] )
VAR _recent_test_score = 
    CALCULATE (
        SUM ( 'Table'[Wert] ),
        REMOVEFILTERS ( 'Table'[Testrang] ),
        'Table'[Testrang] = _recent_test
            &amp;amp;&amp;amp; 'Table'[Name] = _name
            &amp;amp;&amp;amp; 'Table'[Test] = _test_type
    )
VAR _prev_test = _recent_test - 1
VAR _prev_test_score =
    CALCULATE (
        SUM ( 'Table'[Wert] ),
        REMOVEFILTERS ( 'Table'[Testrang] ),
        'Table'[Testrang] = _prev_test
            &amp;amp;&amp;amp; 'Table'[Name] = _name
            &amp;amp;&amp;amp; 'Table'[Test] = _test_type
    )
VAR _current_minus_prev =
    _recent_test_score - _prev_test_score
RETURN
    _current_minus_prev&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this works for you please accept as the solution for visibilty of others.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 16:19:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331285#M171947</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-12-16T16:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331986#M171984</link>
      <description>&lt;P&gt;Thanks for the replies from&amp;nbsp;mark_endicott.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="899356" data-lia-user-login="Valentin09" class="lia-mention lia-mention-user"&gt;Valentin09&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on your description, I created simple data:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try the following DAX formula:&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;Difference = 
VAR _count=CALCULATE(COUNT('Table'[Name]),ALLEXCEPT('Table','Table'[Name]))
VAR _current=MAX('Table'[Testrang])
VAR CurrentTestrang=CALCULATE(SUM('Table'[Wert]),FILTER(ALLEXCEPT('Table','Table'[Name]),'Table'[Testrang]=_current))
VAR PreviousTestrang=CALCULATE(SUM('Table'[Wert]),FILTER(ALLEXCEPT('Table','Table'[Name]),'Table'[Testrang]=_current-1))
return
IF(_count&amp;gt;1&amp;amp;&amp;amp;_current&amp;gt;1,CurrentTestrang-PreviousTestrang,blank())&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;Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is any post&amp;nbsp;&lt;I&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/I&gt;, then please consider&amp;nbsp;&lt;I&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/I&gt;&amp;nbsp;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 03:11:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4331986#M171984</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-17T03:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4333370#M172048</link>
      <description>&lt;P&gt;This works perfectly! I just had to change -1 to +1, because most recent test has the 1, the penultimate the 2 and so on.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 15:27:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4333370#M172048</guid>
      <dc:creator>Valentin09</dc:creator>
      <dc:date>2024-12-17T15:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract two values based on Rank</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4333389#M172050</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="899356" data-lia-user-login="Valentin09" class="lia-mention lia-mention-user"&gt;Valentin09&lt;/a&gt;&amp;nbsp;- No problem, I missed it saying the current test was 1 in your original description.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm glad you've been able to amend my DAX accordingly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2024 15:36:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-two-values-based-on-Rank/m-p/4333389#M172050</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-12-17T15:36:26Z</dc:date>
    </item>
  </channel>
</rss>

