<?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: Top n Values in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928128#M41838</link>
    <description>&lt;P&gt;Thanks for the reply. I understand the logic of your solution unfortunately I cannot get it to work.&lt;/P&gt;&lt;P&gt;I write the measure as below but it still seems to be totalling up all instances of the top values e.g. the third student has top results of two at 8.5 and 3 at 8 hence a total of 41. Am I doing something stupid!!&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jun 2021 11:50:03 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-06-29T11:50:03Z</dc:date>
    <item>
      <title>Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1927972#M41828</link>
      <description>&lt;P&gt;I am tryng to use Power BI in a school setting and want to be able to get the sum of the top 3 results for each student. I have tried TOPN but the problem is that if a student's top results are say 4 grade 8s then TOPN would return 32 rather than the 24 I want. Any ideas as how to resolve this would be appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 10:24:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1927972#M41828</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T10:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928024#M41834</link>
      <description>&lt;P&gt;Very simple ideas. Use TOPN wrapped in DISTINCT.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 10:52:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928024#M41834</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T10:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928128#M41838</link>
      <description>&lt;P&gt;Thanks for the reply. I understand the logic of your solution unfortunately I cannot get it to work.&lt;/P&gt;&lt;P&gt;I write the measure as below but it still seems to be totalling up all instances of the top values e.g. the third student has top results of two at 8.5 and 3 at 8 hence a total of 41. Am I doing something stupid!!&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 11:50:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928128#M41838</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T11:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928160#M41839</link>
      <description>&lt;P&gt;Then do it the other way round: first DISTINCT, then TOPN. That should definitely get you what you need.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 12:13:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928160#M41839</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T12:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928184#M41840</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[TOPN Sum] =
var topn_ = 3
var Result =
    SUMX(
        DISTINCT( Result[ID] ),
        CALCULATE(
            SUMX(
                TOPN(topn_,
                    DISTINCT( Result[Result] ),
                    Result[Result],
                    DESC
                ),
                Result[Result]
            )
        )
    )
return
    Result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Works correctly also on the Total row...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another way of calculation:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[TOPN Sum] =
var topn_ = 3
var IDsWithTopNResults = 
    GENERATE(
        DISTINCT( Result[ID] ),
        CALCULATETABLE(
            TOPN(topn_,
                DISTINCT( Result[Result] ),
                Result[Result],
                DESC
            )
        )
    )
var Result =
    SUMX(
        IDsWithTopNResults,
        Result[Result]
    )
return
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 29 Jun 2021 12:25:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928184#M41840</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T12:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928259#M41842</link>
      <description>&lt;P&gt;Thanks and sorry for being a pain but your solution works too well. With the list below it gives a result of 21 (sum of the top 3 distinct values), but what I need is to add together the two 8s and&amp;nbsp; then only one of the 7s. I can do this in Excel with the LARGE function but not in DAX.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Art - 8&lt;/LI&gt;&lt;LI&gt;Maths - 8&lt;/LI&gt;&lt;LI&gt;Science - 7&lt;/LI&gt;&lt;LI&gt;Spanish - 7&lt;/LI&gt;&lt;LI&gt;English - 6&lt;/LI&gt;&lt;LI&gt;Music - 5&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 12:54:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928259#M41842</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T12:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928377#M41848</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[TOPN Sum] =
var topn_ = 3
return
SUMX(
    DISTINCT( Result[ID] ),
    CALCULATE(    
        var VisibleSubjects =
            DISTINCT( Result[Subject] )
        var SubjectsOrdered =
            ADDCOLUMNS(
                VisibleSubjects,
                "@SubjectNumber",
                    RANKX(
                        VisibleSubjects,
                        Result[Subject],,
                        ASC,
                        // this option
                        // does not matter
                        // here
                        DENSE 
                    )
            )
        var SubjectNumberMagnitude =
            LEN(
                MAXX(
                    SubjectsOrdered,
                    [@SubjectNumber]
                )
            )
        var ResultWithSubject =
            SUMMARIZE(
                Result,
                Result[Result],
                Result[Subject]
            )
        var Result = 
            SUMX(
                TOPN(topn_,
                    NATURALINNERJOIN(
                        ResultWithSubject,
                        SubjectsOrdered
                    ),
                    Result[Result]
                        * 10^SubjectNumberMagnitude
                        + [@SubjectNumber]
                ),
                Result[Result]
            )
        return
            Result
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 13:57:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928377#M41848</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T13:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928439#M41849</link>
      <description>&lt;P&gt;WOW!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no idea how this works but it does the job. Thanks for all your help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 14:04:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/1928439#M41849</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-29T14:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Top n Values</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/2049688#M46076</link>
      <description>&lt;P&gt;How about trying to get a top ten by client, and by master client? Something like the below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I try to do this in BI using TopN on client name by sales amount, it only filters client name, i.e. if sub client 1 has 300k, and sub client 2 has 200k, it skips to the next master client that has that 200k.&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>Tue, 31 Aug 2021 19:38:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Top-n-Values/m-p/2049688#M46076</guid>
      <dc:creator>bengrove</dc:creator>
      <dc:date>2021-08-31T19:38:16Z</dc:date>
    </item>
  </channel>
</rss>

