<?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 Using TOCSV to Show Top N in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-TOCSV-to-Show-Top-N/m-p/3150491#M112835</link>
    <description>&lt;P&gt;For demonstration, I am using the sample Contoso PBIX (&lt;A href="https://www.microsoft.com/en-us/download/details.aspx?id=46801" target="_blank"&gt;https://www.microsoft.com/en-us/download/details.aspx?id=46801&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;Here we can see a list of countries by their total sales such as.....&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I created a few basic measures for Sales and Rank by Country such as...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sales = SUM('Sales'[SalesAmount])


Ranking on Country = 
IF (
    ISINSCOPE ( 'Geography'[RegionCountryName] ),
    RANKX (
        ALLSELECTED ( 'Geography'[RegionCountryName] ),
        [Sales]
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I am going to use the Rank measure and Sale measure for sorting in my summary table.&amp;nbsp; I also created a parameter table to allow the user to select the Top 5,10,15,20, and 25 countries.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, there are other ways to concatenate the TOP N countries by sales, but this tip is about using the new function called TOCSV.&amp;nbsp; I wrote the following measure that does the following:&lt;/P&gt;&lt;P&gt;1) Summarizes the country and total sales while formatting the [Sales] measure in the summary table.&lt;/P&gt;&lt;P&gt;2) Keep the Top N based on what option is selected from the parameter table or defaults to Top N = 5.&lt;/P&gt;&lt;P&gt;3) Uses the TOCSV to create a comma seperate list.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top N Countries = 
VAR summaryTable = SUMMARIZECOLUMNS('Geography'[RegionCountryName],"TotalSales",FORMAT([Sales]," $#,##"))
VAR keepTopN = TOPN(SELECTEDVALUE('Top N'[Show Top],5),summaryTable,[Ranking on Country],ASC,[TotalSales], DESC) 
VAR concateTheRecords = TOCSV(keepTopN,25,",",FALSE())
RETURN concateTheRecords&lt;/LI-CODE&gt;&lt;P&gt;The results in this example are...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2023 16:00:38 GMT</pubDate>
    <dc:creator>BrianConnelly</dc:creator>
    <dc:date>2023-03-23T16:00:38Z</dc:date>
    <item>
      <title>Using TOCSV to Show Top N</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-TOCSV-to-Show-Top-N/m-p/3150491#M112835</link>
      <description>&lt;P&gt;For demonstration, I am using the sample Contoso PBIX (&lt;A href="https://www.microsoft.com/en-us/download/details.aspx?id=46801" target="_blank"&gt;https://www.microsoft.com/en-us/download/details.aspx?id=46801&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;Here we can see a list of countries by their total sales such as.....&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I created a few basic measures for Sales and Rank by Country such as...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Sales = SUM('Sales'[SalesAmount])


Ranking on Country = 
IF (
    ISINSCOPE ( 'Geography'[RegionCountryName] ),
    RANKX (
        ALLSELECTED ( 'Geography'[RegionCountryName] ),
        [Sales]
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I am going to use the Rank measure and Sale measure for sorting in my summary table.&amp;nbsp; I also created a parameter table to allow the user to select the Top 5,10,15,20, and 25 countries.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, there are other ways to concatenate the TOP N countries by sales, but this tip is about using the new function called TOCSV.&amp;nbsp; I wrote the following measure that does the following:&lt;/P&gt;&lt;P&gt;1) Summarizes the country and total sales while formatting the [Sales] measure in the summary table.&lt;/P&gt;&lt;P&gt;2) Keep the Top N based on what option is selected from the parameter table or defaults to Top N = 5.&lt;/P&gt;&lt;P&gt;3) Uses the TOCSV to create a comma seperate list.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Top N Countries = 
VAR summaryTable = SUMMARIZECOLUMNS('Geography'[RegionCountryName],"TotalSales",FORMAT([Sales]," $#,##"))
VAR keepTopN = TOPN(SELECTEDVALUE('Top N'[Show Top],5),summaryTable,[Ranking on Country],ASC,[TotalSales], DESC) 
VAR concateTheRecords = TOCSV(keepTopN,25,",",FALSE())
RETURN concateTheRecords&lt;/LI-CODE&gt;&lt;P&gt;The results in this example are...&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 16:00:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Using-TOCSV-to-Show-Top-N/m-p/3150491#M112835</guid>
      <dc:creator>BrianConnelly</dc:creator>
      <dc:date>2023-03-23T16:00:38Z</dc:date>
    </item>
  </channel>
</rss>

