Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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
)
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
12 | |
11 | |
7 | |
6 |