<?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 row level sum from 2 fact tables in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968483#M99125</link>
    <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="438895" data-lia-user-login="arjenbos91" class="lia-mention lia-mention-user"&gt;arjenbos91&lt;/a&gt;&amp;nbsp; check out my blogpost for this (the part where you create the measure in the SUM() OVER partition by logic ) hope this helps.&amp;nbsp; :&amp;nbsp;&lt;A href="https://www.iipowerblog.com/post/sum-over-partition-by-in-powerbi" target="_blank"&gt;https://www.iipowerblog.com/post/sum-over-partition-by-in-powerbi&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2022 15:45:37 GMT</pubDate>
    <dc:creator>IIPowerBlog</dc:creator>
    <dc:date>2022-12-14T15:45:37Z</dc:date>
    <item>
      <title>Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2967855#M99105</link>
      <description>&lt;P&gt;I want to calculate an absolute forecast error based on 2 tables. I have made some sample data which reflects my problem:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Fact: Sales (observation per date and category)&lt;/LI&gt;&lt;LI&gt;Fact: Forecast (sales forecast per date)&lt;/LI&gt;&lt;LI&gt;Dim: Date&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Currently using these relationships:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In this example I've prepared the columns 'Forecast'[Actual Amount] and 'Forecast'[Absolute Error] by hand in Excel. But in my real data these are missing and I wish to calculate those with DAX.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data looks like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The results in the blue table is what I want to achieve. The problem is that the Sales table also has an extra dimenion (the Category) and I can't join the Sales and Forecast into 1 table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using a simple&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Absolute Forecast Error = ABS(SUM(Forecast[Forecast]) - SUM(Sales[Amount]))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it calculates the Total wrong. It gives a Total of 1. Which makes sense when substracting both totals. But the Total should be 7. How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My actual data has a lot more dates and I wish to aggregate the absolute forecast error to months, quarters and years.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 12:14:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2967855#M99105</guid>
      <dc:creator>arjenbos91</dc:creator>
      <dc:date>2022-12-14T12:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968449#M99121</link>
      <description>&lt;P&gt;Hey &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="438895" data-lia-user-login="arjenbos91" class="lia-mention lia-mention-user"&gt;arjenbos91&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Instead of making the final result absolute, you should make each line absolute, and take the sum of them.&amp;nbsp;You can do this within a row context, using the SUMX function.&amp;nbsp;You want to do this per date, so date is your relevant row context in this case. You can use these measures:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;forecast =
SUM ( Forecast[Forecast] )&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;sales_amount =
SUM ( Sales[Amount] )&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Absolute Forecast Error =
SUMX ( Date, ABS ( [forecast] - [sales_amount] ) )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 15:34:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968449#M99121</guid>
      <dc:creator>Barthel</dc:creator>
      <dc:date>2022-12-14T15:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968483#M99125</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="438895" data-lia-user-login="arjenbos91" class="lia-mention lia-mention-user"&gt;arjenbos91&lt;/a&gt;&amp;nbsp; check out my blogpost for this (the part where you create the measure in the SUM() OVER partition by logic ) hope this helps.&amp;nbsp; :&amp;nbsp;&lt;A href="https://www.iipowerblog.com/post/sum-over-partition-by-in-powerbi" target="_blank"&gt;https://www.iipowerblog.com/post/sum-over-partition-by-in-powerbi&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 15:45:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968483#M99125</guid>
      <dc:creator>IIPowerBlog</dc:creator>
      <dc:date>2022-12-14T15:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968492#M99126</link>
      <description>&lt;P&gt;Thanks this works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've done some more experimenting and I only get the correct result when I use multiple measures (as in your answer). Why doesn't the following work?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Absolute Forecast Error = SUMX('Date', ABS(SUM(Forecast[Forecast]) - SUM(Sales[Amount]))&lt;/LI-CODE&gt;&lt;P&gt;Or this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Absolute Forecast Error =
VAR f = SUM(Forecast[Forecast])
VAR s = SUM(Sales[Amount])
RETURN SUMX('Date', ABS(f - s))&lt;/LI-CODE&gt;&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 15:50:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968492#M99126</guid>
      <dc:creator>arjenbos91</dc:creator>
      <dc:date>2022-12-14T15:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968516#M99131</link>
      <description>&lt;P&gt;Sorry but this doesn't suit my case. I don't need a separate totals column. My measure needs to aggregate correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The case in your blog I would simply solve by using a table visual using the quantity as values and productname as either rows or columns. No DAX needed. Also the code in your blog has one of the Power BI pitfalls: &lt;A href="https://learn.microsoft.com/en-us/dax/best-practices/dax-avoid-avoid-filter-as-filter-argument" target="_self"&gt;Avoid using FILTER in CALCULATE&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thanks anyway&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 15:58:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968516#M99131</guid>
      <dc:creator>arjenbos91</dc:creator>
      <dc:date>2022-12-14T15:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968532#M99132</link>
      <description>&lt;P&gt;ok thanks for the feedback, its much appreciated. Good luck with getting the solution!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:03:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968532#M99132</guid>
      <dc:creator>IIPowerBlog</dc:creator>
      <dc:date>2022-12-14T16:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate row level sum from 2 fact tables</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968550#M99135</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="438895" data-lia-user-login="arjenbos91" class="lia-mention lia-mention-user"&gt;arjenbos91&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;This is because you have to calculate the amount per date. The above variants calculate the totals and do not take the row context into account, because context transition does not take place. The referenced&amp;nbsp;measures implicitly activate context transition. You could also process it in to one measure by using CALCULATE (which also activates context transition):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Absolute Forecast Error =
SUMX (
    'Date',
    ABS (
        CALCULATE ( SUM ( Forecast[Forecast] ) ) - CALCULATE ( SUM ( Sales[Amount] ) )
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For more info see this article:&amp;nbsp;&lt;A href="https://www.sqlbi.com/articles/understanding-context-transition-in-dax/" target="_blank"&gt;https://www.sqlbi.com/articles/understanding-context-transition-in-dax/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2022 16:11:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-row-level-sum-from-2-fact-tables/m-p/2968550#M99135</guid>
      <dc:creator>Barthel</dc:creator>
      <dc:date>2022-12-14T16:11:39Z</dc:date>
    </item>
  </channel>
</rss>

