Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
Solved! Go to Solution.
Give this a try
CONCATENATEX (
SELECTCOLUMNS (
TOPN (
5,
DISTINCT ( 'Customer'[City] ),
'Customer'[City], ASC
),
"City", 'Customer'[City]
),
[City],
", ",
'Customer'[City], ASC
)
Oh yeah, CONCATENATEX comes with sorting parameters! Thank you, man. This is not a generic sorting function, but it solves the problem 👍
Give this a try
CONCATENATEX (
SELECTCOLUMNS (
TOPN (
5,
DISTINCT ( 'Customer'[City] ),
'Customer'[City], ASC
),
"City", 'Customer'[City]
),
[City],
", ",
'Customer'[City], ASC
)
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |