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
Singularity9
Frequent Visitor

Use Concatenatex and topn to create a string containing the values of column 1, ordered by column 2

Hello. I have a table, Test, with two columns:

 

LocalityPercentage
A1
B2
C3
D4
E-1
F-2

 

I would like to create a measure which lists the positive Localities only in a single string, ordered by Percentage (descending). So in this case it would run "D, C, B and A". I'm using concatenatex and topn to do this.

This is the code I'm using: 

calculate(
Concatenatex(topn(
COUNTROWS(distinct(Test[Locality]))-1, test, Test[Percentage], Desc),Test[Locality], ", ")
&
" and "
&Concatenatex(topn(1, test, Test[Percentage], asc),Test[Locality]),
Test[Percentage]>
0)


It works almost perfectly, but it doesn't give me the answers in order, since TopN doesn't do that. So instead of "D, C, B and A" I get something like "C,B, A and D" - a completely random order. My question is, how can I make sure the Values are concatenated in order? Thanks in advance.

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Singularity9,

 

Try using the CONCATENATEX parameters OrderBy_Expression and Order:

 

Concatenate Measure = CALCULATE (
    CONCATENATEX (
        TOPN (
            COUNTROWS ( DISTINCT ( Test[Locality] ) ) - 1,
            test,
            Test[Percentage], DESC
        ),
        Test[Locality],
        ", ",
        Test[Percentage],
        DESC
    ) & " and "
        & CONCATENATEX ( TOPN ( 1, test, Test[Percentage], ASC ), Test[Locality] ),
    Test[Percentage] > 0
)

 

DataInsights_0-1715703809382.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@Singularity9,

 

Try using the CONCATENATEX parameters OrderBy_Expression and Order:

 

Concatenate Measure = CALCULATE (
    CONCATENATEX (
        TOPN (
            COUNTROWS ( DISTINCT ( Test[Locality] ) ) - 1,
            test,
            Test[Percentage], DESC
        ),
        Test[Locality],
        ", ",
        Test[Percentage],
        DESC
    ) & " and "
        & CONCATENATEX ( TOPN ( 1, test, Test[Percentage], ASC ), Test[Locality] ),
    Test[Percentage] > 0
)

 

DataInsights_0-1715703809382.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

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.