<?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 calculate the absolute aggregate difference between planned vs sold per product each day in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3707252#M144209</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to create a dax measure that will calculate the sum of the absolute differences of products planned and sold for each product on each day. This is quite easy on a spreadsheet but for some reason am struggling in Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my schema:&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;My table looks like this:&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;Im able to get the correct answer for eash line item but when it comes to the total Ive tried a few approaches and all seem to not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ive looked at:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Difference = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; planned = (&lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;('Planned Menus'[Qty]) )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; sold = &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;('SaleLine'[Quantity]) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;('Calendar', &lt;/SPAN&gt;&lt;SPAN&gt;ABS&lt;/SPAN&gt;&lt;SPAN&gt;(planned - sold ))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But I dont think is iterating through each recipeID maybe?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any ideas how I can make this work?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 19 Feb 2024 08:49:34 GMT</pubDate>
    <dc:creator>moesteez</dc:creator>
    <dc:date>2024-02-19T08:49:34Z</dc:date>
    <item>
      <title>Measure to calculate the absolute aggregate difference between planned vs sold per product each day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3707252#M144209</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im trying to create a dax measure that will calculate the sum of the absolute differences of products planned and sold for each product on each day. This is quite easy on a spreadsheet but for some reason am struggling in Power BI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my schema:&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;My table looks like this:&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;Im able to get the correct answer for eash line item but when it comes to the total Ive tried a few approaches and all seem to not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ive looked at:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Difference = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; planned = (&lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;('Planned Menus'[Qty]) )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt;&lt;SPAN&gt; sold = &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;('SaleLine'[Quantity]) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;SUMX&lt;/SPAN&gt;&lt;SPAN&gt;('Calendar', &lt;/SPAN&gt;&lt;SPAN&gt;ABS&lt;/SPAN&gt;&lt;SPAN&gt;(planned - sold ))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;But I dont think is iterating through each recipeID maybe?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any ideas how I can make this work?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Feb 2024 08:49:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3707252#M144209</guid>
      <dc:creator>moesteez</dc:creator>
      <dc:date>2024-02-19T08:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to calculate the absolute aggregate difference between planned vs sold per product each day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3708122#M144258</link>
      <description>&lt;P&gt;&lt;SPAN&gt;It seems like you're trying to calculate the absolute aggregate difference between planned and sold quantities for each product on each day in Power BI using DAX. Your DAX measure looks mostly correct, but it seems you might need to adjust the context in which it operates. You should consider iterating over each product to calculate the absolute difference. Here's how you can modify your DAX measure:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AbsoluteDifference =&lt;BR /&gt;SUMX (&lt;BR /&gt;VALUES ( 'Sales'[RecipeID] ), -- Iterate over each distinct RecipeID&lt;BR /&gt;VAR PlannedQty =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;SUM ( 'Planned Menus'[Qty] ),&lt;BR /&gt;FILTER ( 'Planned Menus', 'Planned Menus'[RecipeID] = 'Sales'[RecipeID] )&lt;BR /&gt;)&lt;BR /&gt;VAR SoldQty =&lt;BR /&gt;CALCULATE (&lt;BR /&gt;SUM ( 'SaleLine'[Quantity] ),&lt;BR /&gt;FILTER ( 'SaleLine', 'SaleLine'[RecipeID] = 'Sales'[RecipeID] )&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;ABS ( PlannedQty - SoldQty )&lt;BR /&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Here's a breakdown of what this measure does:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;It iterates over each distinct RecipeID using the VALUES function.&lt;/LI&gt;&lt;LI&gt;For each RecipeID, it calculates the PlannedQty by summing the quantities from the 'Planned Menus' table where the RecipeID matches the current RecipeID in context.&lt;/LI&gt;&lt;LI&gt;Similarly, it calculates the SoldQty by summing the quantities from the 'SaleLine' table where the RecipeID matches the current RecipeID in context.&lt;/LI&gt;&lt;LI&gt;It calculates the absolute difference between PlannedQty and SoldQty for each RecipeID.&lt;/LI&gt;&lt;LI&gt;Finally, it sums up these absolute differences to get the total absolute difference across all RecipeIDs for each day in the context of your report.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This measure should provide you with the absolute aggregate difference between planned and sold quantities for each product on each day in Power BI. Make sure to adjust the table and column names as per your actual data model.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 19 Feb 2024 13:29:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3708122#M144258</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-02-19T13:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Measure to calculate the absolute aggregate difference between planned vs sold per product each day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3709450#M144330</link>
      <description>&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 02:07:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Measure-to-calculate-the-absolute-aggregate-difference-between/m-p/3709450#M144330</guid>
      <dc:creator>moesteez</dc:creator>
      <dc:date>2024-02-20T02:07:51Z</dc:date>
    </item>
  </channel>
</rss>

