<?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 Incorrect Totals in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Incorrect-Totals/m-p/2802951#M88260</link>
    <description>&lt;P&gt;My problem is as it follows: I have 2 tables, the first one has the amount of products per date and the company ID from where that product is; the second one has the company ID and the company name. In order to calculate the amount of products&amp;nbsp; that each company have in the last date of the selected month I wrote the Dax code as shown below:&lt;/P&gt;&lt;DIV&gt;&lt;FONT color="#3366FF"&gt;AMOUNT =&lt;/FONT&gt; &lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;])))&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;The tables have the format shown below:&lt;BR /&gt;&lt;img /&gt;&lt;P&gt;&lt;BR /&gt;When I put the Company Name as a row header in a matrix visual I am getting the wrong total. I've already tried the SUMMARIZE+SUMX, the IF+HASONFILTER and the SUMX methods but none of these actually worked. The DAX code of my attempts are listed below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT1=&lt;/FONT&gt;&amp;nbsp;&lt;STRONG&gt;SUMX(&lt;/STRONG&gt;CompanyTable,&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]))))&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT2=&amp;nbsp;&lt;BR /&gt;VAR &lt;FONT color="#339966"&gt;X =&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]))))&lt;BR /&gt;&lt;/STRONG&gt;&lt;FONT color="#339966"&gt;RETURN&lt;BR /&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;SUMX(SUMMARIZE(&lt;/STRONG&gt;CompanyTable,CompanyTable&lt;STRONG&gt;[&lt;/STRONG&gt;CompanyName&lt;STRONG&gt;])&lt;/STRONG&gt;,X&lt;STRONG&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT3=&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#3366FF"&gt;VAR &lt;/FONT&gt;&lt;FONT color="#3366FF"&gt;X&lt;/FONT&gt;&lt;FONT color="#3366FF"&gt; =&lt;/FONT&gt;&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable[AvailableAmount]&lt;STRONG&gt;),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable[EventDate]&lt;STRONG&gt;=MAX(&lt;/STRONG&gt;ProductTable[EventDate]&lt;STRONG&gt;))))&lt;BR /&gt;RETURN&lt;BR /&gt;IF(HASONEFILTER(&lt;/STRONG&gt;CompanyTable[CompanyName&lt;STRONG&gt;]),X,SUMX(&lt;/STRONG&gt;CompanyTable,X&lt;STRONG&gt;))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 28 Sep 2022 13:32:37 GMT</pubDate>
    <dc:creator>Gekko1</dc:creator>
    <dc:date>2022-09-28T13:32:37Z</dc:date>
    <item>
      <title>Incorrect Totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Incorrect-Totals/m-p/2802951#M88260</link>
      <description>&lt;P&gt;My problem is as it follows: I have 2 tables, the first one has the amount of products per date and the company ID from where that product is; the second one has the company ID and the company name. In order to calculate the amount of products&amp;nbsp; that each company have in the last date of the selected month I wrote the Dax code as shown below:&lt;/P&gt;&lt;DIV&gt;&lt;FONT color="#3366FF"&gt;AMOUNT =&lt;/FONT&gt; &lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;])))&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;The tables have the format shown below:&lt;BR /&gt;&lt;img /&gt;&lt;P&gt;&lt;BR /&gt;When I put the Company Name as a row header in a matrix visual I am getting the wrong total. I've already tried the SUMMARIZE+SUMX, the IF+HASONFILTER and the SUMX methods but none of these actually worked. The DAX code of my attempts are listed below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT1=&lt;/FONT&gt;&amp;nbsp;&lt;STRONG&gt;SUMX(&lt;/STRONG&gt;CompanyTable,&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]))))&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT2=&amp;nbsp;&lt;BR /&gt;VAR &lt;FONT color="#339966"&gt;X =&lt;/FONT&gt;&amp;nbsp;&lt;/FONT&gt;&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;AvailableAmount&lt;STRONG&gt;]),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]=MAX(&lt;/STRONG&gt;ProductTable&lt;STRONG&gt;[&lt;/STRONG&gt;EventDate&lt;STRONG&gt;]))))&lt;BR /&gt;&lt;/STRONG&gt;&lt;FONT color="#339966"&gt;RETURN&lt;BR /&gt;&lt;FONT color="#000000"&gt;&lt;STRONG&gt;SUMX(SUMMARIZE(&lt;/STRONG&gt;CompanyTable,CompanyTable&lt;STRONG&gt;[&lt;/STRONG&gt;CompanyName&lt;STRONG&gt;])&lt;/STRONG&gt;,X&lt;STRONG&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#3366FF"&gt;ATTEMPT3=&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT color="#3366FF"&gt;VAR &lt;/FONT&gt;&lt;FONT color="#3366FF"&gt;X&lt;/FONT&gt;&lt;FONT color="#3366FF"&gt; =&lt;/FONT&gt;&lt;STRONG&gt;CALCULATE(SUM(&lt;/STRONG&gt;ProductTable[AvailableAmount]&lt;STRONG&gt;),FILTER(&lt;/STRONG&gt;ProductTable,ProductTable[EventDate]&lt;STRONG&gt;=MAX(&lt;/STRONG&gt;ProductTable[EventDate]&lt;STRONG&gt;))))&lt;BR /&gt;RETURN&lt;BR /&gt;IF(HASONEFILTER(&lt;/STRONG&gt;CompanyTable[CompanyName&lt;STRONG&gt;]),X,SUMX(&lt;/STRONG&gt;CompanyTable,X&lt;STRONG&gt;))&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 28 Sep 2022 13:32:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Incorrect-Totals/m-p/2802951#M88260</guid>
      <dc:creator>Gekko1</dc:creator>
      <dc:date>2022-09-28T13:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Incorrect Totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Incorrect-Totals/m-p/2805223#M88431</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="395855" data-lia-user-login="Gekko1" class="lia-mention lia-mention-user"&gt;Gekko1&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If your goal is to calculate the amount of products&amp;nbsp; that each company have in the last date of the selected month, please try following steps:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This is my test table:&lt;/SPAN&gt;&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;Create a new column:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Month = FORMAT([Date],"mmmm")&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try following measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = CALCULATE(
    SUM('Table'[Amount]),
        FILTER('Table','Table'[Month] = SELECTEDVALUE('Table'[Month]) &amp;amp;&amp;amp; 
                        'Table'[Company ID] = SELECTEDVALUE('Table'[Company ID]) &amp;amp;&amp;amp; 
                        'Table'[Date] = MAX('Table'[Date]))
                     )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this the result you want?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Yadong Fang&lt;/P&gt;
&lt;P&gt;If this post&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;helps&lt;/EM&gt;&lt;/STRONG&gt;, then please consider&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 07:26:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Incorrect-Totals/m-p/2805223#M88431</guid>
      <dc:creator>v-yadongf-msft</dc:creator>
      <dc:date>2022-09-29T07:26:20Z</dc:date>
    </item>
  </channel>
</rss>

