Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

TopN sorting (Used in dynamic title)

I have used the dax formula written here for a dynamic title, based on the selection of a filter. In my case, I am using week numbers instead of days of the week, and have therefore amended the dax as such. 

 

It is working, however my issue is that when multiple week numbers are selected, they are not in any numerical order. As an example, when I select weeks 10, 11, 12 it displays as "Report Data for Weeks 11, 10 and 12". I've tried adding in sorting within TOPN, but all it does is interfere with the lastselected value delimiter, so it then appears as "11, 10, 12 and". 

 

VAR AllButLastSelectedWeek =
    TOPN ( NumberOfSelectedWeeks - 1, SelectedWeeks, SelectedWeeks, Asc )
 
Can anyone help please? 

 

Title2 =
VAR SelectedWeeks =
    VALUES ( table[Week_No] )
VAR NumberOfSelectedWeeks =
    COUNTROWS ( SelectedWeeks )
VAR NumberOfPossibleWeeks =
    COUNTROWS ( ALL ( table[Week_No] ) )
VAR AllButLastSelectedWeek =
    TOPN ( NumberOfSelectedWeeks - 1, SelectedWeeks)
VAR LastSelectedWeek =
    EXCEPT ( SelectedWeeks, AllButLastSelectedWeek )
RETURN
    "Report Data "
        & IF (
            NumberOfSelectedWeeks = NumberOfPossibleWeeks,
            "- All",
            "For Week"
                & IF (
                    NumberOfSelectedWeeks = 1,
                    " ",
                    "s " & CONCATENATEX (
                       AllButLastSelectedWeek,
                      table[Week_No],
                       ", " )
                        & " And "
                )
                & LastSelectedWeek        )
2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

The Title2 measure looks OK. Based on my test, it works well as below. I have attached my sample file at bottom. 

vjingzhang_0-1683615740937.png

In addition, what is the data type of "Week_No" column? I recommend that you change it to Whole number type. This will make it be sorted correctly.  

vjingzhang_1-1683615809825.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

Thank you for looking at this for me - I can confirm that week_no is already classified as Whole Number. This is how it's written, and the result I'm getting.

I have also tried

Week_No = VALUE(WEEKNUM(table[Invoice Date],2))
which makes no difference.

 

Sh4dow85_1-1683627679055.png

 

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors