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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Vendelin
New Member

New column sorted alphabetically

I have column A, with many letters separated by a comma. I want a new column B, where i sort column A alphabetically.

See example Fig 1

Fig 1

Column A Column B
A,B,CA,B,C
B,C,AA,B,C
A,C,BA,B,C
B,A,CA,B,C
B,C,DB,C,D
D,A,CA,C,D
C,E,AA,C,E

 

Can anyone help me with a code for this? 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Vendelin 

please try 

ColumnB =
VAR String = 'Table'[ColumnA]
VAR Items =
    SUBSTITUTE ( String, ",", "|" )
VAR Length =
    COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T1 =
    GENERATESERIES ( 1, Length, 1 )
VAR T2 =
    SELECTCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
RETURN
    CONCATENATEX ( T2, [@Item], ",", [@Item], ASC )

View solution in original post

2 REPLIES 2
Vendelin
New Member

Thanks tamerj1 it work perfekt 🙂

tamerj1
Super User
Super User

Hi @Vendelin 

please try 

ColumnB =
VAR String = 'Table'[ColumnA]
VAR Items =
    SUBSTITUTE ( String, ",", "|" )
VAR Length =
    COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T1 =
    GENERATESERIES ( 1, Length, 1 )
VAR T2 =
    SELECTCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) )
RETURN
    CONCATENATEX ( T2, [@Item], ",", [@Item], ASC )

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.