<?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 profit only if item exists in two years in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2820514#M89554</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;BR /&gt;&lt;BR /&gt;Thank you so much for your response. Sorry to share that the result wasnt the intended one but it was able to modify the measures and was able to achieve the intended results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a disconnected Year table and used the below measures.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Profit in current year = 
VAR SelectedYear =
    SELECTEDVALUE( 'Year'[Year] ) 
VAR CurrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CurrentItems, PreviousItems )
RETURN
  {CALCULATE(sum('Table'[profit]),FILTER('Table', 'Table'[Item] in CommonItems), FILTER('Table', 'Table'[Year] = selectedyear) )}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Profit in prior year = 
VAR SelectedYear =
    SELECTEDVALUE( 'Year'[Year] )-1
    
VAR CurrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear + 1
    )
VAR CommonItems =
    INTERSECT ( CurrentItems, PreviousItems )
RETURN
  {CALCULATE(sum('Table'[Profit]),FILTER('Table', 'Table'[Item] in CommonItems), FILTER('Table', 'Table'[Year] = selectedyear))}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AnthonyJoseph&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Oct 2022 17:51:42 GMT</pubDate>
    <dc:creator>AnthonyJoseph</dc:creator>
    <dc:date>2022-10-05T17:51:42Z</dc:date>
    <item>
      <title>calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753707#M85028</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would need to calculate profit for different items for the slected year and its previous year based on a condition (i.e. calcuate profit for items that were present in the selected year and its previous year).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My input table is like below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;Item&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Profit&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;143&lt;/TD&gt;&lt;TD&gt;936&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&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&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;259&lt;/TD&gt;&lt;TD&gt;622&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;726&lt;/TD&gt;&lt;TD&gt;330&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;379&lt;/TD&gt;&lt;TD&gt;157&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;192&lt;/TD&gt;&lt;TD&gt;148&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;156&lt;/TD&gt;&lt;TD&gt;376&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when year 2021 is selected, I want to list down the items that are common in both the years 2020 and 2021, then calculate their sums. Pasted below is the expected result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Please can somone guide me here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AnthonyJoseph&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 17:50:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753707#M85028</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-07T17:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753766#M85039</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;2021 Profit =
VAR SelectedYear =
    SELECTEDVALUE ( TableName[Year] )
VAR CarrentItems =
    VALUES ( TableName[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( TableName[Item] ),
        TableName[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CarrentItems, PreviousItems )
RETURN
    CALCULATE ( SUM ( TableName[Profit] ), CommonItems )&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 07 Sep 2022 18:44:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753766#M85039</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-07T18:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753795#M85045</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;. The solution worked for 2021 year selection but I'm not able to get the desired number for 2020 by modifing the current dax to 2020. Please can you share your thoughts on this as well...&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 19:18:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2753795#M85045</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-07T19:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2754162#M85074</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have data for 2019?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 02:43:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2754162#M85074</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-08T02:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2757078#M85275</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; There is no data for 2019 but when I select 2021 in the slicer then the output should display both present year value and the prior year value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the measure, I was able to get the present year value for 2021 but unable to get the value for 2020.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to show difference between the values in 2021 and 2020 showing only the common items that are there in both years... i.e. when I select 2021 in the slicer it should automatically show the value for its prior year 2020 and present year 2021 ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Can you please help me to get the values for column "Profit in 2020" column --highlighted in red.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 05:16:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2757078#M85275</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-09T05:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2757134#M85282</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I got your point. Let's do it in a more dynamic way. The two measures will be "Selected Year Profit" and "Previous to Selected Year Profit" as follows&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Selected Year Profit =
VAR SelectedYear =
    SELECTEDVALUE ( TableName[Year] )
VAR CarrentItems =
    VALUES ( TableName[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( TableName[Item] ),
        TableName[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CarrentItems, PreviousItems )
RETURN
    CALCULATE ( SUM ( TableName[Profit] ), CommonItems )&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;Previous Year Profit =
VAR SelectedYear =
    SELECTEDVALUE ( TableName[Year] ) - 1
VAR CarrentItems =
    VALUES ( TableName[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( TableName[Item] ),
        TableName[Year] = SelectedYear - 2
    )
VAR CommonItems =
    INTERSECT ( CarrentItems, PreviousItems )
RETURN
    CALCULATE ( SUM ( TableName[Profit] ), CommonItems )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 09 Sep 2022 05:58:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2757134#M85282</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-09T05:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762224#M85652</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; I tried using two measures but still not getting the previous year value.... Pasted below the screenshot for the measures:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AnthonyJoseph&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 14:50:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762224#M85652</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-12T14:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762228#M85653</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you selected a year?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 14:51:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762228#M85653</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-12T14:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762548#M85671</link>
      <description>&lt;P&gt;Yes, I have selected 2021 year... If incase, multiple years are selected then both value appears blank.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 17:10:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762548#M85671</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-12T17:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762710#M85684</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Would you please provide dummy sample as per the original source data?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2022 19:33:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762710#M85684</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-12T19:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762861#M85693</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;You can try this. I hope it helps!&lt;/P&gt;
&lt;P&gt;&lt;A title="Profit if in Prev Year" href="https://drive.google.com/file/d/1nOZcrJW3WLN-Dlz0-gCAyRU7nbFrqilf/view?usp=sharing" target="_self"&gt;https://drive.google.com/file/d/1nOZcrJW3WLN-Dlz0-gCAyRU7nbFrqilf/view?usp=sharing&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 00:53:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2762861#M85693</guid>
      <dc:creator>Whitewater100</dc:creator>
      <dc:date>2022-09-13T00:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2766380#M85928</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for reaching out to us.&lt;/P&gt;
&lt;P&gt;I just want to confirm if you resolved this issue? If yes,&amp;nbsp;&lt;U&gt;you can accept the answer helpful as the solution&lt;/U&gt;&amp;nbsp;&lt;STRONG&gt;or&lt;/STRONG&gt;&amp;nbsp;&lt;U&gt;share you method and accept it as solution&lt;/U&gt;, thanks for your contribution to improve Power BI.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If you need more help, please let me know.&lt;/STRONG&gt;&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 _Tang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, 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, 14 Sep 2022 07:31:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2766380#M85928</guid>
      <dc:creator>v-xiaotang</dc:creator>
      <dc:date>2022-09-14T07:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2772365#M86349</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; The sample data is pasted below and I would be very excited to solve this with measures....&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;Item&lt;/TD&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Profit&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;143&lt;/TD&gt;&lt;TD&gt;936&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD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R&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;259&lt;/TD&gt;&lt;TD&gt;622&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;726&lt;/TD&gt;&lt;TD&gt;330&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2021&lt;/TD&gt;&lt;TD&gt;379&lt;/TD&gt;&lt;TD&gt;157&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;192&lt;/TD&gt;&lt;TD&gt;148&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;2022&lt;/TD&gt;&lt;TD&gt;156&lt;/TD&gt;&lt;TD&gt;376&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 06:09:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2772365#M86349</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-09-16T06:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2772496#M86359</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="86868" data-lia-user-login="AnthonyJoseph" class="lia-mention lia-mention-user"&gt;AnthonyJoseph&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I think I did a very stupid mistake in the Previous Year Measure. Please refer to attached sample file&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Selected Year Profit = 
VAR SelectedYear =
    SELECTEDVALUE ( 'Table'[Year] )
VAR CarrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CarrentItems, PreviousItems )
RETURN
    CALCULATE ( SUM ( 'Table'[Profit] ), CommonItems )&lt;/LI-CODE&gt;&lt;LI-CODE lang="javascript"&gt;Previous Year Profit = 
VAR SelectedYear =
    SELECTEDVALUE ( 'Table'[Year] ) - 1
VAR CarrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CarrentItems, PreviousItems )
RETURN
    CALCULATE ( SUM ( 'Table'[Profit] ), CommonItems )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 06:52:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2772496#M86359</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-16T06:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: calculate profit only if item exists in two years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2820514#M89554</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;BR /&gt;&lt;BR /&gt;Thank you so much for your response. Sorry to share that the result wasnt the intended one but it was able to modify the measures and was able to achieve the intended results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a disconnected Year table and used the below measures.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Profit in current year = 
VAR SelectedYear =
    SELECTEDVALUE( 'Year'[Year] ) 
VAR CurrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear - 1
    )
VAR CommonItems =
    INTERSECT ( CurrentItems, PreviousItems )
RETURN
  {CALCULATE(sum('Table'[profit]),FILTER('Table', 'Table'[Item] in CommonItems), FILTER('Table', 'Table'[Year] = selectedyear) )}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Profit in prior year = 
VAR SelectedYear =
    SELECTEDVALUE( 'Year'[Year] )-1
    
VAR CurrentItems =
    VALUES ( 'Table'[Item] )
VAR PreviousItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Item] ),
        'Table'[Year] = SelectedYear + 1
    )
VAR CommonItems =
    INTERSECT ( CurrentItems, PreviousItems )
RETURN
  {CALCULATE(sum('Table'[Profit]),FILTER('Table', 'Table'[Item] in CommonItems), FILTER('Table', 'Table'[Year] = selectedyear))}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;AnthonyJoseph&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 17:51:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/calculate-profit-only-if-item-exists-in-two-years/m-p/2820514#M89554</guid>
      <dc:creator>AnthonyJoseph</dc:creator>
      <dc:date>2022-10-05T17:51:42Z</dc:date>
    </item>
  </channel>
</rss>

