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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi,
I have the following DAX to dynamically select the TOP N values for % of followers from each city but unable to define the sort by descending in this DAX.
What changes can i make to define this descending sort?
Here's the DAX
The sorting should be in descending order.
Thank you.
Solved! Go to Solution.
To fix the sorting issue, add two arguments to CONCATENATEX:
VAR ResultString =
CONCATENATEX(
ResultTable,
[Percentage] & " in " & [City],
", ",
[Percentage], DESC
)
A possible alternative version of the measure consolidating some steps:
Top Cities KPI =
VAR N = SELECTEDVALUE ( 'Top'[top] )
VAR TotalFAN =
COUNT ( 'Table (2)'[FAN ID] )
VAR CityPercentage =
SUMMARIZECOLUMNS (
'Table (2)'[City],
"Percentage", DIVIDE ( COUNT ( 'Table (2)'[FAN ID] ), TotalFan )
)
VAR TopCityPercentage =
TOPN ( N, CityPercentage, [Percentage], DESC )
VAR ResultString =
CONCATENATEX (
TopCityPercentage,
FORMAT ( [Percentage], "0.0%" ) & " in " & 'Table (2)'[City],
", ",
[Percentage], DESC
)
RETURN
ResultString
Hi @abhishek_2593
Top Cities KPI =
VAR N = SELECTEDVALUE('Top'[top])
VAR CityTable =
SUMMARIZE(
'Table (2)',
'Table (2)'[City],
"TotalFAN", COUNT('Table (2)'[FAN ID])
)
VAR TotalFAN =
CALCULATE(COUNT('Table (2)'[FAN ID]))
VAR TopCitiesTable =
TOPN(N, CityTable, [TotalFAN], DESC)
-- Add both numeric and formatted percentage
VAR ResultTable =
ADDCOLUMNS(
TopCitiesTable,
"NumericPercentage", DIVIDE([TotalFAN], TotalFAN),
"FormattedPercentage", FORMAT(DIVIDE([TotalFAN], TotalFAN), "0.0%")
)
-- Use line break with UNICHAR(10)
VAR ResultString =
CONCATENATEX(
ResultTable,
[FormattedPercentage] & " in " & [City],
UNICHAR(10),
[NumericPercentage], DESC
)
RETURN
ResultString
If this answers your questions, kindly accept it as a solution and give kudos.
Hi @abhishek_2593
Top Cities KPI =
VAR N = SELECTEDVALUE('Top'[top])
VAR CityTable =
SUMMARIZE(
'Table (2)',
'Table (2)'[City],
"TotalFAN", COUNT('Table (2)'[FAN ID])
)
VAR TotalFAN =
CALCULATE(COUNT('Table (2)'[FAN ID]))
VAR TopCitiesTable =
TOPN(N, CityTable, [TotalFAN], DESC)
-- Add both numeric and formatted percentage
VAR ResultTable =
ADDCOLUMNS(
TopCitiesTable,
"NumericPercentage", DIVIDE([TotalFAN], TotalFAN),
"FormattedPercentage", FORMAT(DIVIDE([TotalFAN], TotalFAN), "0.0%")
)
-- Use line break with UNICHAR(10)
VAR ResultString =
CONCATENATEX(
ResultTable,
[FormattedPercentage] & " in " & [City],
UNICHAR(10),
[NumericPercentage], DESC
)
RETURN
ResultString
If this answers your questions, kindly accept it as a solution and give kudos.
To fix the sorting issue, add two arguments to CONCATENATEX:
VAR ResultString =
CONCATENATEX(
ResultTable,
[Percentage] & " in " & [City],
", ",
[Percentage], DESC
)
A possible alternative version of the measure consolidating some steps:
Top Cities KPI =
VAR N = SELECTEDVALUE ( 'Top'[top] )
VAR TotalFAN =
COUNT ( 'Table (2)'[FAN ID] )
VAR CityPercentage =
SUMMARIZECOLUMNS (
'Table (2)'[City],
"Percentage", DIVIDE ( COUNT ( 'Table (2)'[FAN ID] ), TotalFan )
)
VAR TopCityPercentage =
TOPN ( N, CityPercentage, [Percentage], DESC )
VAR ResultString =
CONCATENATEX (
TopCityPercentage,
FORMAT ( [Percentage], "0.0%" ) & " in " & 'Table (2)'[City],
", ",
[Percentage], DESC
)
RETURN
ResultString
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.