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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Sh4dow85
Frequent Visitor

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 @Sh4dow85 

 

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.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.