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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
Community Champion
Community Champion

@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.

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@RitaP_123 Try:

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


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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