<?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 Measure to sum a column bases on another tables column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2620997#M76343</link>
    <description>&lt;P&gt;Hello guys, it's my first post here and I'm very glad to be part of this forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recently I'm trying to deal with a logical sum in DAX and to be honest I not dealing with it really well...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 3 tables:&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;&lt;img /&gt;&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 sum the MB52[Quantity] based on Current and Old Keys, reaching this result:&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;Identifying [Current Key] and suming the quantity of the [Old. Key] with owns [Current Key] quantity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code but with no sucess &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[Sum. Quantity] =&lt;BR /&gt;IF&lt;BR /&gt;(&lt;BR /&gt;&lt;BR /&gt;'KEYS'[Old. Key] &amp;lt;&amp;gt; "";&lt;BR /&gt;&lt;BR /&gt;CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Old. Key])) + CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Current Key]));&lt;BR /&gt;&lt;BR /&gt;SUM(MB52[Quantity])&lt;BR /&gt;&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apreciate a lot your help and thanks anyway &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jul 2022 00:12:10 GMT</pubDate>
    <dc:creator>paulomartins</dc:creator>
    <dc:date>2022-07-06T00:12:10Z</dc:date>
    <item>
      <title>Measure to sum a column bases on another tables column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2620997#M76343</link>
      <description>&lt;P&gt;Hello guys, it's my first post here and I'm very glad to be part of this forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Recently I'm trying to deal with a logical sum in DAX and to be honest I not dealing with it really well...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 3 tables:&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;&lt;img /&gt;&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 sum the MB52[Quantity] based on Current and Old Keys, reaching this result:&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;Identifying [Current Key] and suming the quantity of the [Old. Key] with owns [Current Key] quantity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code but with no sucess &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[Sum. Quantity] =&lt;BR /&gt;IF&lt;BR /&gt;(&lt;BR /&gt;&lt;BR /&gt;'KEYS'[Old. Key] &amp;lt;&amp;gt; "";&lt;BR /&gt;&lt;BR /&gt;CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Old. Key])) + CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Current Key]));&lt;BR /&gt;&lt;BR /&gt;SUM(MB52[Quantity])&lt;BR /&gt;&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apreciate a lot your help and thanks anyway &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 00:12:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2620997#M76343</guid>
      <dc:creator>paulomartins</dc:creator>
      <dc:date>2022-07-06T00:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to sum a column bases on another tables column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2622298#M76434</link>
      <description>&lt;P&gt;Assuming that you have a one-to-many relationship from Products to Keys and no relationships between MB52 and the other tables, then you could try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sum of quantity =
CALCULATE (
    SUM ( MB52[Quantity] ),
    TREATAS (
        UNION ( VALUES ( Keys[Current Key] ), VALUES ( Keys[Old Key] ) ),
        MB52[Key]
    )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 11:14:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2622298#M76434</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-07-06T11:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to sum a column bases on another tables column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2623217#M76514</link>
      <description>&lt;P&gt;Sorry, I forgot to post the tables relationship...&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;Because I'm using power pivot I had to do some changes, using INTERSECT instead TREATAS and use DISTINCT on MB52[Key].&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final result is just a sum of Current Keys quantity and putting the Old Keys quantity in a null key &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;!--  StartFragment   --&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Sum of quantity = &lt;/SPAN&gt;&lt;SPAN class=""&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;                 SUM&lt;/SPAN&gt;&lt;SPAN class=""&gt; ( MB52[Quantity] ); &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;                 INTERSECT&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;                          UNION&lt;/SPAN&gt;&lt;SPAN class=""&gt;( &lt;/SPAN&gt;&lt;SPAN class=""&gt;VALUES&lt;/SPAN&gt;&lt;SPAN class=""&gt; ( KEYS[Current Key] ); &lt;/SPAN&gt;&lt;SPAN class=""&gt;VALUES&lt;/SPAN&gt;&lt;SPAN class=""&gt;( KEYS[Old. Key] ) );&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;                          DISTINCT&lt;/SPAN&gt;&lt;SPAN class=""&gt;(MB52[Key])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;                )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;           )&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Result:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 17:40:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2623217#M76514</guid>
      <dc:creator>paulomartins</dc:creator>
      <dc:date>2022-07-06T17:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to sum a column bases on another tables column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2626454#M76668</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="409249" data-lia-user-login="paulomartins" class="lia-mention lia-mention-user"&gt;paulomartins&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create measure.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure =
var _old=
CALCULATE(SUM('MB52'[Quantity]),
FILTER(ALL(MB52),
'MB52'[Key]=MAX('Keys'[Old.Key])))
var _current=
CALCULATE(SUM('MB52'[Quantity]),
FILTER(ALL(MB52),
'MB52'[Key]=MAX('Keys'[Current Key])))
var _sum=
_old + _current
return
IF(
_sum = BLANK() ,0,_sum)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Measure 2 =
SUMX(
    FILTER(ALL('Keys'),
    'Keys'[Current Key] = MAX('Products'[Currrent Key])),
    [Measure])&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If you need pbix, please click &lt;A href="https://m365x668238-my.sharepoint.com/:u:/g/personal/yangliu_m365x668238_onmicrosoft_com/ESaixHtfl7NGr6XWkaCHNM0Bcee7NcDtTOIx7WOw-H-sJg?e=57dzxC" target="_blank"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 01:51:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2626454#M76668</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-07-08T01:51:10Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to sum a column bases on another tables column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2629344#M76858</link>
      <description>&lt;P&gt;It is what I was trying to do!&lt;BR /&gt;&lt;BR /&gt;Thank you so much&amp;nbsp;Anonymous&lt;/a&gt;, you helped me to reach the result and learn a lot about DAX with this problem!&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2022 20:28:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-sum-a-column-bases-on-another-tables-column/m-p/2629344#M76858</guid>
      <dc:creator>paulomartins</dc:creator>
      <dc:date>2022-07-10T20:28:52Z</dc:date>
    </item>
  </channel>
</rss>

