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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.

 


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!:
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)

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors