<?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: TopN DAX measure for filter table _ topN doesn't work properly in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444125#M130911</link>
    <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;A href="https://1drv.ms/u/s!AsDP3LYI8umspko83dOj1K-zSJ7-?e=psDBKJ" target="_blank" rel="noopener"&gt;Example_TopN.pbix&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Sep 2023 08:19:47 GMT</pubDate>
    <dc:creator>ThxAlot</dc:creator>
    <dc:date>2023-09-23T08:19:47Z</dc:date>
    <item>
      <title>TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3443841#M130895</link>
      <description>&lt;P&gt;Dear Power Bi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please help me solve an issue with my Dax measures?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The idea is that I want to retrieve top 3 negative value in a dataset, and I use this DAX measure below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Var top3 = TOPN(3,&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FILTER(SUMMARIZE('Sale table','Date'[Quarter],'Date'[Year]),[Sales_QTD] &amp;lt; 0),&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Sales_QTD],DESC)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Var top3_sum = SUMX(top3,[Sales_QTD])&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Var total_sum_negative &amp;nbsp;= SUMX(FILTER(ALL(New_Function[Functions]),[Sales_QTD] &amp;lt; 0), [Sales_QTD])&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Var Othervalue = total_sum_negative - top3_sum&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Var Otherselected = SELECTEDVALUE(New_Function[Functions]) = "Other"&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;Return&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;If(HASONEVALUE(New_Function[Functions]),&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; if(not Otherselected,&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CALCULATE([Sales_QTD],KEEPFILTERS(top3)), &lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Othervalue),&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; total_sum_negative)&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;However, when I drop this measure to the table, the topN function is totally not working. The result is that I got all negative value in the table in 1 quarter and other category equals total negative value. Below is the result I got, which is not my intention. What I want to retrieve in the matrix is A, C &amp;amp; D and Other will be the total of rest (including D, E, F, S, L, G, R)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;P&gt;So, please if anyone has solution, I would be very thankful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thank you both&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="404599" data-lia-user-login="TomasAndersson" class="lia-mention lia-mention-user"&gt;TomasAndersson&lt;/a&gt;&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="474658" data-lia-user-login="ThxAlot" class="lia-mention lia-mention-user"&gt;ThxAlot&lt;/a&gt;&amp;nbsp;so much for your solution. It worked now on my real dataset!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 09:51:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3443841#M130895</guid>
      <dc:creator>Mai_Ng2587</dc:creator>
      <dc:date>2023-09-26T09:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444106#M130909</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified your top10 variable a bit. You need to select all "functions" because otherwise each function is just compared to itself, which will always result in it being "top 3".&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top 3new = 

Var top10 = TOPN(3,
                ALLSELECTED(New_Function[Functions]),
            [Sales_QTD], ASC)
Var top10_sum = SUMX(top10,[Sales_QTD])
Var total_sum_negative  = SUMX(FILTER(ALL(New_Function[Functions]),[Sales_QTD] &amp;lt; 0), [Sales_QTD])
Var Othervalue = total_sum_negative - top10_sum
Var Otherselected = SELECTEDVALUE(New_Function[Functions]) = "Other"

Return
If(HASONEVALUE(New_Function[Functions]),
    if(not Otherselected,
        CALCULATE([Sales_QTD],KEEPFILTERS(top10)), 
        Othervalue),
    total_sum_negative)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;This solution gives the top 3 largest (negative) values. D and E have an equal size so if you want to only D to show for example you would need another criteria (maybe you can wrap this in a Top N based on function name or something like that). I think it works more as you want anyway.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;This is a great source for working with Top N and Others so I recommend you look into it for more resources.&amp;nbsp;&lt;A href="https://goodly.co.in/top-n-and-others-power-bi/" target="_blank"&gt;https://goodly.co.in/top-n-and-others-power-bi/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 08:01:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444106#M130909</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2023-09-23T08:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444125#M130911</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;A href="https://1drv.ms/u/s!AsDP3LYI8umspko83dOj1K-zSJ7-?e=psDBKJ" target="_blank" rel="noopener"&gt;Example_TopN.pbix&lt;/A&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 08:19:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444125#M130911</guid>
      <dc:creator>ThxAlot</dc:creator>
      <dc:date>2023-09-23T08:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444176#M130913</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for the solution but this solution is missing the calculation of Other (which should be the sum of other functions but not the sum of top 3 functions). How should I calculate Other in this way?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 09:42:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444176#M130913</guid>
      <dc:creator>Mai_Ng2587</dc:creator>
      <dc:date>2023-09-23T09:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444198#M130915</link>
      <description>&lt;P&gt;Row of Other is already there; it sums up (-9, -8, -8, -6, -4, -1).&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 10:10:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444198#M130915</guid>
      <dc:creator>ThxAlot</dc:creator>
      <dc:date>2023-09-23T10:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444214#M130916</link>
      <description>&lt;P&gt;Hi Tomas,&lt;/P&gt;&lt;P&gt;Thank you for helping me modify the Dax measure. Do you know why I can't use the filter table [&lt;STRONG&gt;FILTER(SUMMARIZE('Sale table','Date'[Quarter],'Date'[Year]),[Sales_QTD] &amp;lt; 0)&lt;/STRONG&gt;] in my topN dax formular? In my real data, unfortunately, if I use Allselected instead of filter &amp;amp; summarize, I somehow got the whole value through all year instead of being filtered by&amp;nbsp;&lt;STRONG&gt;'Date'[Quarter],'Date'[Year].&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 10:43:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444214#M130916</guid>
      <dc:creator>Mai_Ng2587</dc:creator>
      <dc:date>2023-09-23T10:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444224#M130919</link>
      <description>&lt;P&gt;&amp;nbsp;I won't be near a computer for a few hours but can look into it later today.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I didn't consider the time period but maybe you can have both? What happens if you add that filter in addition to ALLSELECTED?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 11:31:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444224#M130919</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2023-09-23T11:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444252#M130920</link>
      <description>&lt;P&gt;I tried again with your solution and found the error in my real dataset that make this solution doesn't work. Thank you so much. Now it is solved!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 20:17:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444252#M130920</guid>
      <dc:creator>Mai_Ng2587</dc:creator>
      <dc:date>2023-09-23T20:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444431#M130937</link>
      <description>&lt;P&gt;Thank you for fixing sample files. Helps a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I spent too much time trying to get the DAX to work, but it seems it was mostly a modelling issue. I just changed the relationship between New_Function and Dim_Tab to a one-to-many instead:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way, the same measure from earlier works.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Don't ask me exactly why. Maybe the lack of Dim_Tab filtered out "Other" from New_Function as well so that it wasn't included in the filter and Otherselected never returned True? Not sure. It looks better now at least. Only negatives are counted, but I think that was what you were looking for? Not difficult to change the filter condition otherwise.&lt;BR /&gt;&lt;BR /&gt;I tested adding an extra Top N to a new measure to only return three values, even in a tie. In case that's something you want to use.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top 3new no ties = 

Var top10 = 
TOPN( //One top N to only select three values
    3,
        TOPN(  //if this top n that calculates sales returns more than three functions
            3,
            FILTER(ALL(New_Function[Function]),[Sales_QTD] &amp;lt; 0), //You could use "&amp;lt;&amp;gt; 0" if you want to allow positive values as well
            [Sales_QTD],
            ASC
        ),
    New_Function[Function], //right now the tie breaker Top N is dependent on the function name
    ASC
)
Var top10_sum = SUMX(top10,[Sales_QTD])
Var total_sum_negative  = SUMX(FILTER(ALL(New_Function[Function]),[Sales_QTD] &amp;lt; 0), [Sales_QTD])
Var Othervalue = total_sum_negative - top10_sum
Var Otherselected = SELECTEDVALUE(New_Function[Function]) = "Other"

Return
If(HASONEVALUE(New_Function[Function]),
    if(not Otherselected,
        CALCULATE('Sale table'[Sales_QTD],KEEPFILTERS(top10)), 
        Othervalue),
    total_sum_negative)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 23 Sep 2023 21:58:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444431#M130937</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2023-09-23T21:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444666#M131003</link>
      <description>&lt;P&gt;Thank you for your help &lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;. I fixed the modelling issue earlier same as your suggestion and got the correct value in my measure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, your new tesing measure with the nested topN is very helpful as now I know that I can use topN with filter as well. Many thanks!!!!!&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 10:37:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444666#M131003</guid>
      <dc:creator>Mai_Ng2587</dc:creator>
      <dc:date>2023-09-24T10:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: TopN DAX measure for filter table _ topN doesn't work properly</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444667#M131004</link>
      <description>&lt;P&gt;Great, glad it worked!&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 10:40:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/TopN-DAX-measure-for-filter-table-topN-doesn-t-work-properly/m-p/3444667#M131004</guid>
      <dc:creator>TomasAndersson</dc:creator>
      <dc:date>2023-09-24T10:40:51Z</dc:date>
    </item>
  </channel>
</rss>

