<?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: Select the Top 5 projects in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4752866#M181968</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks and regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Jul 2025 04:25:21 GMT</pubDate>
    <dc:creator>v-nmadadi-msft</dc:creator>
    <dc:date>2025-07-04T04:25:21Z</dc:date>
    <item>
      <title>Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743821#M181642</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to get top 5 projects through a DAX measure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;The data is as follows:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;1. Revenue Table has columns projectID, Project Name, Customer, Region, Month, Revenue&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;2. COGS Table has Project ID, Month, COGS which stands for cost of goods sold&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;3. Projects Table which has Project ID, Project Manager, Start date, End date, Status which has all projects set to active&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;There are two measures, one which calculates the Gross margin by subtracting the total COGS from the total Revenue and gross margin percentage which divides the gross margin over by the revenue&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want to get the Top 5 projects by Gross Margin and by Revenue. Initially I looked into TOPN:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Top &lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt; Projects &lt;/SPAN&gt;&lt;SPAN&gt;by&lt;/SPAN&gt;&lt;SPAN&gt; Gross Margin =&lt;/SPAN&gt; &lt;SPAN&gt;TOPN&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;Projects&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Gross Margin]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;DESC&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Top &lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt; Projects &lt;/SPAN&gt;&lt;SPAN&gt;by&lt;/SPAN&gt;&lt;SPAN&gt; Revenue =&lt;/SPAN&gt; &lt;SPAN&gt;TOPN&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;5&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;Projects&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;[Total Revenue]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;DESC&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;and created tables with it, but I realized I needed it in DAX form so that it would return the following output:&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Project ID&lt;/TD&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PRJ1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PRJ4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PRJ5&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PRJ2&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PRJ3&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV&gt;Or just the projects table sorted by top 5 would also work.&lt;BR /&gt;Anyone know how to go on about this?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 25 Jun 2025 13:56:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743821#M181642</guid>
      <dc:creator>Kareem77</dc:creator>
      <dc:date>2025-06-25T13:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743913#M181645</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To identify the top 5 projects, you will first need to establish your base measures. These measures calculate the total revenue, total cost of goods sold, and the resulting gross margin. These form the foundation for any subsequent ranking calculations.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Revenue = SUM(Revenue[Revenue])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Total COGS = SUM(COGS[COGS])&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Gross Margin = [Total Revenue] - [Total COGS]&lt;/LI-CODE&gt;
&lt;P&gt;One effective method to get your desired output is to create a new calculated table within your data model. This approach generates a static table containing only the top 5 projects ranked by a specific measure. This can be particularly useful for summary pages or when you need a fixed list of top performers. The TOPN function is combined with ADDCOLUMNS and RANKX to first identify the top projects and then assign them a specific rank.&lt;/P&gt;
&lt;P&gt;For the Top 5 projects ranked by Gross Margin, you can use the following DAX expression to create a new table. This code snippet first finds the top 5 projects based on the [Gross Margin] measure and then adds a "Rank" column to display their standing.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top 5 Projects by Gross Margin = 
ADDCOLUMNS (
    TOPN ( 5, VALUES ( Projects[Project ID] ), [Gross Margin], DESC ),
    "Rank", RANKX ( ALL ( Projects[Project ID] ), [Gross Margin],, DESC )
)&lt;/LI-CODE&gt;
&lt;P&gt;Similarly, you can create another calculated table to display the Top 5 projects based on Total Revenue. The logic is identical, but it references the [Total Revenue] measure instead of the gross margin.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Top 5 Projects by Revenue = 
ADDCOLUMNS (
    TOPN ( 5, VALUES ( Projects[Project ID] ), [Total Revenue], DESC ),
    "Rank", RANKX ( ALL ( Projects[Project ID] ), [Total Revenue],, DESC )
)&lt;/LI-CODE&gt;
&lt;P&gt;An alternative, more dynamic approach involves creating a ranking measure that can be used within any visual in your report. This method does not create a physical table but calculates the rank on the fly, allowing it to respond to other filters and slicers in your report. You would create a measure to rank projects and then apply a filter on a table or matrix visual to display only the top 5.&lt;/P&gt;
&lt;P&gt;To implement this, you can write a ranking measure for Gross Margin. The use of HASONEVALUE ensures the rank is calculated only at the project level, and ALLSELECTED allows the ranking to adjust based on active filters in the report.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Gross Margin Rank = 
IF (
    HASONEVALUE ( Projects[Project ID] ),
    RANKX ( ALLSELECTED ( Projects[Project ID] ), [Gross Margin],, DESC, Dense )
)&lt;/LI-CODE&gt;
&lt;P&gt;After creating this measure, you would add Project ID and the [Gross Margin Rank] measure to a table visual. Then, in the visual's filter pane, you would set a filter on Gross Margin Rank to show only values that are "less than or equal to 5". This provides a flexible view of the top projects that can change dynamically as a user interacts with a dashboard, for example, by selecting a specific region or time period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jun 2025 15:04:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743913#M181645</guid>
      <dc:creator>DataNinja777</dc:creator>
      <dc:date>2025-06-25T15:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743919#M181646</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;You could add 2 measures using RANKX&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Project Rank by Gross Margin = 
RANKX(
    ALL('Projects'[Project ID]),
    [Gross Margin],
    ,
    DESC,
    Dense
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Project Rank by Revenue = 
RANKX(
    ALL('Projects'[Project ID]),
    [Total Revenue],
    ,
    DESC,
    Dense
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then add the 2 measures to a table, apply filters to the visual:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Project Rank by Gross Margin is less than or equal to 5&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If preferred, you could add a calculated table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top 5 Projects by Gross Margin Table = 
VAR RankedProjects =
    ADDCOLUMNS(
        'Projects',
        "Rank", RANKX(ALL('Projects'), [Gross Margin], , DESC, Dense)
    )
RETURN
    FILTER(RankedProjects, [Rank] &amp;lt;= 5)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jun 2025 15:08:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4743919#M181646</guid>
      <dc:creator>wardy912</dc:creator>
      <dc:date>2025-06-25T15:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4744003#M181649</link>
      <description>&lt;P&gt;Thanks everyone. Seems like exact way I want isn't directly doable purely in DAX, but with other ways.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jun 2025 16:00:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4744003#M181649</guid>
      <dc:creator>Kareem77</dc:creator>
      <dc:date>2025-06-25T16:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4745064#M181686</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;May I ask if you have resolved this issue with advice provided by &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="475583" data-lia-user-login="wardy912" class="lia-mention lia-mention-user"&gt;wardy912&lt;/a&gt;&amp;nbsp; and &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="608865" data-lia-user-login="DataNinja777" class="lia-mention lia-mention-user"&gt;DataNinja777&lt;/a&gt;&amp;nbsp;? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster. If not please let us know the update on your issue so that we can look into it again.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jun 2025 12:23:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4745064#M181686</guid>
      <dc:creator>v-nmadadi-msft</dc:creator>
      <dc:date>2025-06-26T12:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4745221#M181699</link>
      <description>&lt;P&gt;Hi Kareem77&lt;/P&gt;&lt;P&gt;it is surely doable in DAX, please provide dummy sample data in tables we can import in Power BI and make sure you get the righe result&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jun 2025 13:31:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4745221#M181699</guid>
      <dc:creator>FBergamaschi</dc:creator>
      <dc:date>2025-06-26T13:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4747764#M181814</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If our responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jun 2025 04:10:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4747764#M181814</guid>
      <dc:creator>v-nmadadi-msft</dc:creator>
      <dc:date>2025-06-30T04:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4752866#M181968</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks and regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jul 2025 04:25:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4752866#M181968</guid>
      <dc:creator>v-nmadadi-msft</dc:creator>
      <dc:date>2025-07-04T04:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Select the Top 5 projects</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4753710#M181996</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="643650" data-lia-user-login="Kareem77" class="lia-mention lia-mention-user"&gt;Kareem77&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-pm-slice="0 0 []"&gt;To calculate the top 5 projects by Gross Margin or Revenue using DAX and return them in a structured form (like showing the Project ID and Rank in a table), you can use the RANKX function instead of TOPN directly, as TOPN returns a table and cannot be used directly in a measure that outputs a scalar value. Start by creating the base measures for Total Revenue, Total COGS, and Gross Margin. Then, use RANKX to create a measure that ranks each project based on the chosen metric. For example, RANKX(ALL('Projects'[Project ID]), [Gross Margin], , DESC, DENSE) will rank all projects by their Gross Margin in descending order. After that, create a filtering measure that checks whether a project’s rank is less than or equal to 5. This flag can then be used in a table visual filter to display only the top 5 projects. This approach keeps the logic dynamic and reusable across visuals without manually filtering each table. It also ensures you can present both the Project ID and its rank, which is useful for reporting or export scenarios.&lt;/P&gt;
&lt;P data-pm-slice="0 0 []"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jul 2025 05:30:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Select-the-Top-5-projects/m-p/4753710#M181996</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-07-05T05:30:52Z</dc:date>
    </item>
  </channel>
</rss>

