<?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: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005230#M156385</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625628" data-lia-user-login="qqqqqwwwweeerrr" class="lia-mention lia-mention-user"&gt;qqqqqwwwweeerrr&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for this. I just had to modify it a little bit and it works perfectly. I was really overcomplicating it with my use of nested TOPNs with KEEPFILTERS.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top 3 multiple test = 
VAR RankCode = RANKX(
    ALLSELECTED(Table[Product_code]),[Sum Euros All Time],,DESC,Dense
)

VAR RankOrigin = 
    RANKX(
        ALLSELECTED(Table[Origin_COuntry]),[Sum Euros All Time],,DESC,Dense
    )

VAR RankDestination =
    RANKX(
        ALLSELECTED(Table[Destination_Country]),[Sum Euros All Time],,DESC,Dense
    )

VAR RankAll =
SWITCH(
    TRUE,
    ISINSCOPE(Table[Destination_Country]),RankDestination,
    ISINSCOPE(Table[Origin_Country]),RankOrigin,
    ISINSCOPE(Table[Product_code]),RankCode  
)

RETURN
IF(
    RankAll &amp;lt;= 3, [SumEuros],BLANK()
)&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 22 Jun 2024 19:06:39 GMT</pubDate>
    <dc:creator>TFRec</dc:creator>
    <dc:date>2024-06-22T19:06:39Z</dc:date>
    <item>
      <title>Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/3999962#M155889</link>
      <description>&lt;P&gt;I need to provide a matrix wherein I show the top 3 product codes, those codes' top 3 countries of origin, and those origin countries' top 3 destination countries.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I tried to use the below formula&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;Test Top 3 with multiple levels keep filter = 
VAR TOPNVALUE = 3
VAR TOPNCODE = TOPN(TOPNVALUE, ALLSELECTED(Table[Product_code]),[Sum Euros All Time])
VAR TOPNORIGINCOUNTRY = CALCULATETABLE(
    TOPN(TOPNVALUE, ALLSELECTED(Table[Origin_Country]),[Sum Euros All Time]),
    KEEPFILTERS(TOPNCODE)
)
VAR TOPNDESTINATIONCOUNTRY = CALCULATETABLE(
    TOPN(TOPNVALUE, ALLSELECTED(Table[Destination_Country]),[Sum Euros All Time]),
    KEEPFILTERS(TOPNCODE),
    KEEPFILTERS(TOPNORIGINCOUNTRY)
)


 
Return
CALCULATE(
    [SumEuros],
    KEEPFILTERS(TOPNCODE),
    KEEPFILTERS(TOPNORIGINCOUNTRY),
    KEEPFILTERS(TOPNDESTINATIONCOUNTRY)
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to work for most part, except that for some origin countries of some codes, for some reason it only shows one destination country.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I initially thought that maybe it was just that the origin in country only had one destination country, but no, it has multiple ones. As a matter of fact, for some reason, the total in the origin country (CR, 28.576 million) is the accurate total of the top 3 countries despite it only showing 1 top country.&lt;BR /&gt;&lt;BR /&gt;The sum formulas referenced in the first DAX formula do not seem to be the issue from what I have tested, but just in case they are:&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;Sum Euros All Time = 
VAR time_period_min = MINX(ALLSELECTED(Table[Date]),Table[Date])
VAR time_period_max = MAXX(ALLSELECTED(Table[Date]),Table[Date])

Return CALCULATE(
            [SumEuros],
            ALL(Table[Date]),
            Table[Date]&amp;gt;=time_period_min,
            Table[Date]&amp;lt;=time_period_max
        )&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SumEuros = SUM(Table[Sales])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 19:04:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/3999962#M155889</guid>
      <dc:creator>TFRec</dc:creator>
      <dc:date>2024-06-22T19:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4000732#M155890</link>
      <description>&lt;P&gt;You need to take extra care to use separate calculations for each category.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide sample data that covers your issue or question &lt;STRONG&gt;completely&lt;/STRONG&gt;, in a &lt;STRONG&gt;usable&lt;/STRONG&gt; format (not as a screenshot).&lt;BR /&gt;&lt;BR /&gt;Do not include sensitive information or anything not related to the issue or question. &lt;BR /&gt;&lt;BR /&gt;If you are unsure how to upload data please refer to &lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;Please show the expected outcome based on the sample data you provided. &lt;BR /&gt;&lt;BR /&gt;Want faster answers? &lt;A href="https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523" target="_blank"&gt;https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2024 21:19:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4000732#M155890</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-06-19T21:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4002361#M156048</link>
      <description>&lt;P&gt;Hello &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Thank you for the help. I have uploaded a pbix using publicly available trade data to replicate the issue at&amp;nbsp;&lt;A href="https://we.tl/t-KFNe32hvK9?" target="_blank" rel="noopener"&gt;https://we.tl/t-KFNe32hvK9?&lt;/A&gt;&amp;nbsp;(hope it is all right to give a WeTransfer link, it was mentioned on the upload data link as one of the ok mediums).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You will see there that for code "27090090" under partner country "NL" it only shows "BE" and "DE", but it should also show "ES" as they are the third biggest declarant country with 191 Million EUR for the code and partner country in question.&lt;BR /&gt;&lt;BR /&gt;Edit: I initially accidentally replied to topic first.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 15:12:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4002361#M156048</guid>
      <dc:creator>TFRec</dc:creator>
      <dc:date>2024-06-20T15:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4002826#M156108</link>
      <description>&lt;P&gt;on the top two levels do you want to show the total level value or only the value contributed by the underlying top 3?&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;</description>
      <pubDate>Thu, 20 Jun 2024 22:30:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4002826#M156108</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-06-20T22:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4004872#M156320</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Thank you very much for having taken the time to look into this. Looking to have the&amp;nbsp;&lt;SPAN&gt;value contributed by the underlying top 3, as it is working in your approach. Am however struggling to change the formula in such a way that it still does the top 3 for the other two upper levels as well.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 05:16:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4004872#M156320</guid>
      <dc:creator>TFRec</dc:creator>
      <dc:date>2024-06-22T05:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4004878#M156321</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="510986" data-lia-user-login="TFRec" class="lia-mention lia-mention-user"&gt;TFRec&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;lbendlin already provided a very good approach, but still, if you seeking another way of doing that you can check this video this is not exact but with some modification this might help you to attain solution:&amp;nbsp;&lt;A href="https://youtu.be/cs2AwJljBrQ?si=yQR7T5WZZMfTaSDh" target="_blank" rel="noopener"&gt;https://youtu.be/cs2AwJljBrQ?si=yQR7T5WZZMfTaSDh&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!&lt;BR /&gt;Check for more intersing solution here: &lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;&lt;A class="" href="http://www.youtube.com/@Howtosolveprobem" target="_blank" rel="noopener"&gt;www.youtube.com/@Howtosolveprobem&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 05:45:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4004878#M156321</guid>
      <dc:creator>qqqqqwwwweeerrr</dc:creator>
      <dc:date>2024-06-22T05:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005129#M156372</link>
      <description>&lt;P&gt;You will have to create three calculated tables, either materialized or as part of the measure (there might be severe performance issues in the latter approach, especially with your amount of data).&amp;nbsp; You need to start from the lowest level as I showed, and then need to use the result of that for the next level, and then the result of that for the top level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Certainly doable but rather complex. Think about softening your requirement, or finding a graphical solution instead (like a decomposition tree)&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 15:36:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005129#M156372</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-06-22T15:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005230#M156385</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="625628" data-lia-user-login="qqqqqwwwweeerrr" class="lia-mention lia-mention-user"&gt;qqqqqwwwweeerrr&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for this. I just had to modify it a little bit and it works perfectly. I was really overcomplicating it with my use of nested TOPNs with KEEPFILTERS.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top 3 multiple test = 
VAR RankCode = RANKX(
    ALLSELECTED(Table[Product_code]),[Sum Euros All Time],,DESC,Dense
)

VAR RankOrigin = 
    RANKX(
        ALLSELECTED(Table[Origin_COuntry]),[Sum Euros All Time],,DESC,Dense
    )

VAR RankDestination =
    RANKX(
        ALLSELECTED(Table[Destination_Country]),[Sum Euros All Time],,DESC,Dense
    )

VAR RankAll =
SWITCH(
    TRUE,
    ISINSCOPE(Table[Destination_Country]),RankDestination,
    ISINSCOPE(Table[Origin_Country]),RankOrigin,
    ISINSCOPE(Table[Product_code]),RankCode  
)

RETURN
IF(
    RankAll &amp;lt;= 3, [SumEuros],BLANK()
)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 22 Jun 2024 19:06:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005230#M156385</guid>
      <dc:creator>TFRec</dc:creator>
      <dc:date>2024-06-22T19:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nested (3 levels) TOPN using Power BI DAX not working for categories but working for other</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005232#M156386</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Thank you very much for the help. I fear creating new tables I would impede a lot of the dynamic use of slicers, filters, etc. on the report unless I went the route of using new tables just for the list of values and then still dynamically calculate the values associated to them (which is doable), so I ended up using the approach indicated by another user.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2024 19:10:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Nested-3-levels-TOPN-using-Power-BI-DAX-not-working-for/m-p/4005232#M156386</guid>
      <dc:creator>TFRec</dc:creator>
      <dc:date>2024-06-22T19:10:25Z</dc:date>
    </item>
  </channel>
</rss>

