<?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: Calculate function with condition on numeric value (previously based on DateAdd) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138506#M111954</link>
    <description>&lt;P&gt;&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;BR /&gt;Thank you, it works like a charm.&amp;nbsp;&lt;BR /&gt;An additional question I have, why doesn`t the measure work if I place it on another chart with a different x-axis?&lt;BR /&gt;I`m replacing the [New] column on this new chart with a text field [New FY] that has 1 to 1 values as such in the same table:&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY1&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY2&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY3&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 10:40:13 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-03-17T10:40:13Z</dc:date>
    <item>
      <title>Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136870#M111835</link>
      <description>&lt;P&gt;I`m trying to adjust the following formula after the column type I am using changed from date to Numeric.&amp;nbsp;&lt;BR /&gt;Here is the previous calcualtion - which is working fine:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;--&lt;BR /&gt;Target = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&amp;nbsp;T&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;SUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;metrics&lt;/SPAN&gt;&lt;SPAN&gt;[Sales]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;DATEADD&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'metrics'&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;,+&lt;/SPAN&gt;&lt;SPAN&gt;2&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;0.1&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;IF&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;T&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;T&lt;/SPAN&gt;&lt;SPAN&gt;,CALCULATE(SUM(metrics[Sales]),DATEADD('metrics'[Date],-2,YEAR))*0.1&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;I no longer have that [Date] column, I Instead have a numeric field (which i need to keep numeric) and should replace it in the formula to become something like:&lt;BR /&gt;IF(T&amp;lt;&amp;gt;0,T,CALCULATE(SUM(metrics[Sales]),DATEADD('metrics'[New],-2,YEAR))*0.1)&lt;BR /&gt;Obviously it`s not working and I was wondering how can I make the formula function again.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:51:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136870#M111835</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-16T16:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136883#M111836</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are using a numeric field instead of a date field in your formula, you cannot use the DATEADD function to add or subtract years from the value in the column. Instead, you need to use a mathematical operation to subtract the appropriate number of years from the value in the column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Assuming your numeric field is called 'New', the adjusted formula should be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="2" color="#993300"&gt;Target =&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="2" color="#993300"&gt;VAR T = CALCULATE(SUM(metrics[Sales]), 'metrics'[New] + 2)*0.1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" size="2" color="#993300"&gt;RETURN IF(T &amp;lt;&amp;gt; 0, T, CALCULATE(SUM(metrics[Sales]), 'metrics'[New] - 2)*0.1)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this formula, we use the plus and minus operators to add or subtract the number of years from the value in the 'New' column. Note that we use single quotes around the column name, as we are referring to a column in the same table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Best regards,&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/isaac-chavarria-artavia-38b982184/" target="_self" rel="nofollow noopener noreferrer"&gt;Isaac Chavarria&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;SPAN&gt;, then please consider&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Accepting it as the solution&amp;nbsp;and giving Kudos&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 16:59:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136883#M111836</guid>
      <dc:creator>ichavarria</dc:creator>
      <dc:date>2023-03-16T16:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136989#M111855</link>
      <description>&lt;P&gt;Thanks Isaac.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The issue I`m facing with the formula is that it`s returning the value as if we are not subtracting or adding 2.&lt;BR /&gt;Sample data and results vs required results are:&lt;BR /&gt;New&amp;nbsp; &amp;nbsp; Sales&amp;nbsp; &amp;nbsp; &amp;nbsp;Target&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Desired Values of Target&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 60&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 17:46:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3136989#M111855</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-16T17:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138410#M111947</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Target =
VAR CurrentNew =
    MAX ( 'metrics'[New] )
VAR T2 =
    CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew + 2 ) * 0.1
VAR T_2 =
    CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew - 2 ) * 0.1
RETURN
    COALESCE ( T2, T_2 )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:01:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138410#M111947</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-17T10:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138506#M111954</link>
      <description>&lt;P&gt;&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;BR /&gt;Thank you, it works like a charm.&amp;nbsp;&lt;BR /&gt;An additional question I have, why doesn`t the measure work if I place it on another chart with a different x-axis?&lt;BR /&gt;I`m replacing the [New] column on this new chart with a text field [New FY] that has 1 to 1 values as such in the same table:&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY1&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY2&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FY3&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:40:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138506#M111954</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-17T10:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138521#M111956</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Please try?&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Target =
VAR CurrentNew =
    MAX ( 'metrics'[New] )
VAR T2 =
    CALCULATE (
        SUM ( metrics[Sales] ),
        'metrics'[New] = CurrentNew + 2,
        ALL ( 'metrics' )
    ) * 0.1
VAR T_2 =
    CALCULATE (
        SUM ( metrics[Sales] ),
        'metrics'[New] = CurrentNew - 2,
        ALL ( 'metrics' )
    ) * 0.1
RETURN
    COALESCE ( T2, T_2 )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:45:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138521#M111956</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2023-03-17T10:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate function with condition on numeric value (previously based on DateAdd)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138542#M111959</link>
      <description>&lt;P&gt;&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;BR /&gt;Works perfectly, I just changed ALL to ALLSELECTED cause I have some filters applied.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 10:54:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-function-with-condition-on-numeric-value-previously/m-p/3138542#M111959</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-17T10:54:24Z</dc:date>
    </item>
  </channel>
</rss>

