<?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 Need help calculating totals which keep duplicating values in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4356432#M172954</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;not sure if it's just forgetting how to do DAX after a couple of weeks of break or what, but I have a problem that I can't quite seem to solve.&amp;nbsp;&lt;BR /&gt;I have a sales, returns and order item-cost table. Please note - some of the tables are connected via DirectQuery, so I can't add columns. I'm having trouble calculating the total of the returned items-costs (which is the sum of each items (returns / ordered qty) * item's cost)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;(using concat for illustration purposes, it is supposed to be a sumx)&lt;BR /&gt;my issue is that the totals values for when there are more than one items is duplicated. For the returned item costs of OrderA, I expect 5 + 10 = 15, but i'm getting 30 + 30 = 60 instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached a pbix below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2025 06:17:49 GMT</pubDate>
    <dc:creator>vicky_</dc:creator>
    <dc:date>2025-01-09T06:17:49Z</dc:date>
    <item>
      <title>Need help calculating totals which keep duplicating values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4356432#M172954</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;not sure if it's just forgetting how to do DAX after a couple of weeks of break or what, but I have a problem that I can't quite seem to solve.&amp;nbsp;&lt;BR /&gt;I have a sales, returns and order item-cost table. Please note - some of the tables are connected via DirectQuery, so I can't add columns. I'm having trouble calculating the total of the returned items-costs (which is the sum of each items (returns / ordered qty) * item's cost)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;(using concat for illustration purposes, it is supposed to be a sumx)&lt;BR /&gt;my issue is that the totals values for when there are more than one items is duplicated. For the returned item costs of OrderA, I expect 5 + 10 = 15, but i'm getting 30 + 30 = 60 instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached a pbix below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2025 06:17:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4356432#M172954</guid>
      <dc:creator>vicky_</dc:creator>
      <dc:date>2025-01-09T06:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating totals which keep duplicating values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4356854#M172965</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="430689" data-lia-user-login="vicky_" class="lia-mention lia-mention-user"&gt;vicky_&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is in the costadj variable. When subtotaling rows, VALUES(Orders[ItemID]) gets all ItemIDs under the current OrderID, not the ItemID of the current row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the corrected Measure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;returned item costs = 
CONCATENATEX(
    VALUES(Orders[ItemID]), 
        var ratio = CALCULATE(DIVIDE([Return Qty (measure)], SUM(Orders[OrderQty]), 0))
        var costadj = CALCULATE(SUM('Order Items Cost'[Cost]) * ratio, TREATAS({Orders[ItemID]}, 'Order Items Cost'[Item])) 
        RETURN costadj
    , ", ")&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you~&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2025 09:29:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4356854#M172965</guid>
      <dc:creator>xifeng_L</dc:creator>
      <dc:date>2025-01-09T09:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help calculating totals which keep duplicating values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4357865#M172996</link>
      <description>&lt;P&gt;That worked like a charm. Thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2025 21:18:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Need-help-calculating-totals-which-keep-duplicating-values/m-p/4357865#M172996</guid>
      <dc:creator>vicky_</dc:creator>
      <dc:date>2025-01-09T21:18:32Z</dc:date>
    </item>
  </channel>
</rss>

