<?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: How to create top 5 previous year, allowing a this year / last year comparison in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588520#M175786</link>
    <description>&lt;P&gt;That doesn't work getting the same values as the query I posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2025 17:59:18 GMT</pubDate>
    <dc:creator>jasemilly</dc:creator>
    <dc:date>2025-02-27T17:59:18Z</dc:date>
    <item>
      <title>How to create top 5 previous year, allowing a this year / last year comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588355#M175770</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;I have created Clustered Column Chart that shows top 5 by category for the whole date range.&amp;nbsp; Broken down by year/month.&amp;nbsp; This works great.&amp;nbsp; It handles if a category has a month were it would be outside the top 5.&amp;nbsp; It's the top 5 for the date range and breaks down what these top 5 did each month.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;From Aport To Htl Top 5 Countries = 

VAR TopFive = 
    TOPN(
        5, 
        SUMMARIZE(
            ALLSELECTED(MergedToHtlFromAirport),
            Country[Country], 
            "TotalSales", [Total # Rows From Airport]
        ), 
        [TotalSales], 
        DESC
    )

RETURN
CALCULATE(
    [Total # Rows From Airport],
    KEEPFILTERS( TopFive )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have taken this measure and altered to try and look at the previous year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I can compare year on year change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Feb 2024 shows 1092 and happy with this LY showa 1146, this should be 1092.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the measure I created for the LY measure&amp;nbsp;it doesn't quite work correctly and returns the top 5 qty for each month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than the top 5 for the date range and then showing the breakdown for each month.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;From Aport To Htl Journeys Top 5 Countries LY = 
  
 VAR TopFivePrevYear = 
    TOPN(
        5, 
        SUMMARIZE(
		CalculateTable(
	            ALLSELECTED(MergedToHtlFromAirport),
        		SamePeriodLastYear('Date'[date]  )
	            ),	
	    Country[Country], 
            "TotalSales", [Total # Rows From Airport]
        ), 
        [TotalSales], 
        DESC
    )

RETURN

CALCULATE(
    [Total # Rows From Airport],
    KEEPFILTERS( TopFivePrevYear ),
    SAMEPERIODLASTYEAR('Date'[Date])
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 16:11:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588355#M175770</guid>
      <dc:creator>jasemilly</dc:creator>
      <dc:date>2025-02-27T16:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to create top 5 previous year, allowing a this year / last year comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588426#M175781</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;From Aport To Htl Journeys Top 5 Countries LY =
VAR TopFivePrevYear =
    TOPN (
        5,
        ADDCOLUMNS (
            SUMMARIZE ( ALLSELECTED ( MergedToHtlFromAirport ), Country[Country] ),
            "TotalSales", CALCULATE ( [Total # Rows From Airport], SAMEPERIODLASTYEAR ( 'Date'[date] ) )
        ),
        [TotalSales], DESC
    )
RETURN
    CALCULATE (
        [Total # Rows From Airport],
        KEEPFILTERS ( TopFivePrevYear ),
        SAMEPERIODLASTYEAR ( 'Date'[Date] )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;I added the ADDCOLUMNS around SUMMARIZE as you shouldn't use SUMMARIZE to generate calculated columns, always use ADDCOLUMNS or SELECTCOLUMNS for that.&lt;/P&gt;
&lt;P&gt;The main problem I think is that you had the SAMEPERIODLASTYEAR in the wrong place. You want it when you are calculating the total, not when you are doing the ALLSELECTED.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 16:54:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588426#M175781</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2025-02-27T16:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create top 5 previous year, allowing a this year / last year comparison</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588520#M175786</link>
      <description>&lt;P&gt;That doesn't work getting the same values as the query I posted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 17:59:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-create-top-5-previous-year-allowing-a-this-year-last-year/m-p/4588520#M175786</guid>
      <dc:creator>jasemilly</dc:creator>
      <dc:date>2025-02-27T17:59:18Z</dc:date>
    </item>
  </channel>
</rss>

