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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RitaP_123
Frequent Visitor

How to sort the multiple column names based on the value in columns?

 

Hi,

I'd like to create a calculated column that show the decending ranking of the column name based on the column values as shown in the "Rank by Code" column. 

I can resolve this case by using "SORTBY" and "CONCATNATE" function in excel but I don't know how to write the DAX formula to sort the column name in Power BI. 

Would you please suggest the DAX formula to achieve this task?

Thanks!

 

RitaP_123_0-1664916100141.png

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @RitaP_123 

It can be realized in Power Query Editor .

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can click "Custom Column" in "Add Column" tab:

vyueyunzhmsft_4-1664958309835.png

(3)We can enter this M language:

Text.Combine(Table.Sort(Record.ToTable(_),{"Value",1})[Name])

vyueyunzhmsft_5-1664958357002.png

(4)Then we can meet your need , the result is as follows:

vyueyunzhmsft_6-1664958383893.png

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

 

 

 

View solution in original post

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @RitaP_123 

It can be realized in Power Query Editor .

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can click "Custom Column" in "Add Column" tab:

vyueyunzhmsft_4-1664958309835.png

(3)We can enter this M language:

Text.Combine(Table.Sort(Record.ToTable(_),{"Value",1})[Name])

vyueyunzhmsft_5-1664958357002.png

(4)Then we can meet your need , the result is as follows:

vyueyunzhmsft_6-1664958383893.png

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

 

 

 

Greg_Deckler
Super User
Super User

@RitaP_123 Also, if you and an Index and then unpivot your A,B,C,D columns you can do this:

Rank by Code Measure = CONCATENATEX('Table2',[Attribute],,[Value],DESC)

PBIX is attached beneath signature that shows both ways.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@RitaP_123 Try:

Rank by Code Column = 
    VAR __Table = { ("A",[A]), ("B",[B]), ("C",[C]), ("D",[D]) }
RETURN
    CONCATENATEX(__Table,[Value1],,[Value2],DESC)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.