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

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

Reply
Martin_D
Super User
Super User

Sorting a single column table within a measure?

Hi,


Is there a way to sort a table within a measure?

The case:

I have a column 'Customer'[City] (could be any text column).

I want to CONCTENATEX the first five city names in the context, based on alphabetical order.

Using
CONCATENATEX ( TOPN ( 5, DISTINCT ( 'Customer'[City] ), [City], ASC ), [City], ", " )
works fine in that way that it always selects the correct cities, but the sorting is not applied to the output table of TOPN, it's just applied as a selection criterion. Since I want to concatenate the cities in alphabetical order, is there a way to express this order in a DAX measure?

 

Thank you very much!

 

Kind regards,

Martin

1 ACCEPTED SOLUTION
aduguid
Super User
Super User

Give this a try 

CONCATENATEX (
    SELECTCOLUMNS (
        TOPN (
            5,
            DISTINCT ( 'Customer'[City] ),
            'Customer'[City], ASC
        ),
        "City", 'Customer'[City]
    ),
    [City],
    ", ",
    'Customer'[City], ASC
)

View solution in original post

2 REPLIES 2
Martin_D
Super User
Super User

Oh yeah, CONCATENATEX comes with sorting parameters! Thank you, man. This is not a generic sorting function, but it solves the problem 👍

aduguid
Super User
Super User

Give this a try 

CONCATENATEX (
    SELECTCOLUMNS (
        TOPN (
            5,
            DISTINCT ( 'Customer'[City] ),
            'Customer'[City], ASC
        ),
        "City", 'Customer'[City]
    ),
    [City],
    ", ",
    'Customer'[City], ASC
)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.