<?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: Error in Grand Total, Selected Value Returning Wrong Total when 'Select ALL' is Clicked in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3832864#M149881</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Based on the information you have provided, the issue with metrics not being updated correctly appears to be related to how the function is interpreted in the slicer context. Please consider modifying all filters in the metrics clearing table except for the filters to be retained:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Distribution X =
VAR TotalMV =
    CALCULATE (
        COUNTROWS ( 'Project Matching' ),
        ALL ( 'Project Matching'[MV.Vendor Name] )
    )
VAR SelectedMV =
    COUNTROWS (
        ALLEXCEPT (
            'Project Matching',
            'Project Matching'[Project Name],
            'Project Matching'[State],
            'Project Matching'[Vendor]
        )
    )
RETURN
    IF ( TotalMV = SelectedMV, TotalMV, SelectedMV )
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;The issue of totals not being aggregated correctly is a common problem in Power BI, especially when working with complex calculations that need to be aggregated in different ways at the total level. You can use this function on a table that follows the current filter context and then perform row-level calculations in that context:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NR Cost =
SUMX (
    VALUES ( 'Project Matching'[Project Name] ),
    VAR mv_rate = [MV Rate] * [Hrs_Alloc]
    RETURN
        IF (
            ISBLANK ( mv_rate )
                || mv_rate = 0,
            [Cost W Inflation] / [Distribution X],
            mv_rate
        )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank" rel="noopener"&gt;How to Get Your Question Answered Quickly - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired out put and pbix file without privacy information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Ada Wang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;, then please consider&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;Accept it as the solution&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2024 07:20:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-04-12T07:20:36Z</dc:date>
    <item>
      <title>Error in Grand Total, Selected Value Returning Wrong Total when 'Select ALL' is Clicked</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3829555#M149737</link>
      <description>&lt;P&gt;Hi everyone, I need help in resolving multiple problems in my power BI visual.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The objective of the visual is to perform a comparative analysis for the actual cost of the Project with the original vendor and compare it to all the possible alternative vendors available on each of the state.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Actual Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Expected Result:&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Here are the important features of my visual which I wanted to work well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Feature 1:&lt;/STRONG&gt;&amp;nbsp; When a user selects alternate vendors using the 'MV. Vendor Name' slicer, it should update the value of 'Distribution X' and show the number of the vendors selected. This will be the basis of the computation where the Actual Hours and Cost will be equally distributed according to the number of alternative suppliers selected.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; The measure for 'Distribution X' is working when the user would manually select on the 'MV. Vendor Name' slicer but once the user hits 'Select All' it will show all the possible suppliers ignoring the filters applied to the other slices (Project Name/State/Vendor)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DAX Code:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Distribution X = 
VAR TotalMV = CALCULATE(COUNTROWS('Project Matching'), ALL('Project Matching'[MV.Vendor Name]))
VAR SelectedMV = COUNTROWS(ALLSELECTED('Project Matching'[MV.Vendor Name]))
RETURN
IF(TotalMV = SelectedMV, TotalMV, SelectedMV)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Feature 2:&lt;/STRONG&gt;&amp;nbsp; After determining the cost and hour allocations, the Cost using the New Rates (NR Cost)&amp;nbsp; is now computed via measure. This will be the basis later on for the row per row computation of the savings.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; The measure 'NR Cost' is calculating correctly on a row per row basis, however, I expect the grandtotal to sum all the rows, however my beginner knowledge is limited. I tried applying the ones in the forum but I think I haven't really understood how Sumx iterator could do really.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dax Code:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;NR Cost = 
VAR mv_rate = [MV Rate] * [Hrs_Alloc]
RETURN
IF(
ISBLANK(mv_rate) || mv_rate = 0 , [Cost W Inflation]/[Distribution X], mv_rate)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Feature 3:&lt;/STRONG&gt;&amp;nbsp; Line per line computation of the Savings/Overage using the measure 'Savings/Over'&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; As you can see in the visual my code is not returning any value at all&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":loudly_crying_face:"&gt;😭&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dax Codes:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Cost_Alloc = 
VAR SelectedMV = COUNTROWS(ALLSELECTED('Project Matching'[MV.Vendor Name]))
VAR CurrentMV = SELECTEDVALUE('Project Matching'[MV.Vendor Name], "Default")
VAR acounta = [Cost W Inflation]
RETURN
IF(
   HASONEVALUE('Project Matching'[MV.Vendor Name]),
   IF(SelectedMV &amp;lt;&amp;gt; 0, acounta / SelectedMV, BLANK()),
   SUMX(VALUES('Project Matching'[MV.Vendor Name]), [Cost W Inflation]) / SelectedMV
)


Savings/Over = [NR Cost]-[Cost_Alloc]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attached my dummy data and pbix in the link, should you need more context about the matter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/drive/folders/1jrzCzmXR7zcFNk5gR4KM5L9VGGHLufbq?usp=sharing" target="_self"&gt;Power BI file and Excel File&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 06:24:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3829555#M149737</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-11T06:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Error in Grand Total, Selected Value Returning Wrong Total when 'Select ALL' is Clicked</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3832864#M149881</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Based on the information you have provided, the issue with metrics not being updated correctly appears to be related to how the function is interpreted in the slicer context. Please consider modifying all filters in the metrics clearing table except for the filters to be retained:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Distribution X =
VAR TotalMV =
    CALCULATE (
        COUNTROWS ( 'Project Matching' ),
        ALL ( 'Project Matching'[MV.Vendor Name] )
    )
VAR SelectedMV =
    COUNTROWS (
        ALLEXCEPT (
            'Project Matching',
            'Project Matching'[Project Name],
            'Project Matching'[State],
            'Project Matching'[Vendor]
        )
    )
RETURN
    IF ( TotalMV = SelectedMV, TotalMV, SelectedMV )
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;The issue of totals not being aggregated correctly is a common problem in Power BI, especially when working with complex calculations that need to be aggregated in different ways at the total level. You can use this function on a table that follows the current filter context and then perform row-level calculations in that context:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NR Cost =
SUMX (
    VALUES ( 'Project Matching'[Project Name] ),
    VAR mv_rate = [MV Rate] * [Hrs_Alloc]
    RETURN
        IF (
            ISBLANK ( mv_rate )
                || mv_rate = 0,
            [Cost W Inflation] / [Distribution X],
            mv_rate
        )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank" rel="noopener"&gt;How to Get Your Question Answered Quickly - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If it does not help, please provide more details with your desired out put and pbix file without privacy information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Ada Wang&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;, then please consider&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;Accept it as the solution&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 07:20:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3832864#M149881</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-12T07:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Error in Grand Total, Selected Value Returning Wrong Total when 'Select ALL' is Clicked</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3836516#M150001</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;@&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;v-yifanw-msft&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&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;Unfortunately the measures you suggested did not work (please see image with Distribution X2 and NR Cost 2 as the new measures.)&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;My goal is take out the tendency of the measure returning the wrong number once 'select all' is clicked by the user in the MV. Vendor Name Slicer.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;For the NR Cost, it seems that we happen to almost the same logic, but the grand total is still not correct.&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;For more context I upload the PBIX file and the ref data in this link:&amp;nbsp;&lt;A href="https://drive.google.com/drive/u/1/folders/1jrzCzmXR7zcFNk5gR4KM5L9VGGHLufbq" target="_blank" rel="noopener"&gt;https://drive.google.com/drive/u/1/folders/1jrzCzmXR7zcFNk5gR4KM5L9VGGHLufbq&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I appreciate your help! Thank you so much&lt;span class="lia-unicode-emoji" title=":loudly_crying_face:"&gt;😭&lt;/span&gt;&lt;/DIV&gt;&lt;/DIV&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&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&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 14 Apr 2024 23:43:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Error-in-Grand-Total-Selected-Value-Returning-Wrong-Total-when/m-p/3836516#M150001</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-04-14T23:43:08Z</dc:date>
    </item>
  </channel>
</rss>

