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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Swapping the values

Hi,

I have two columns, Id and name with multiple values with delimitor and jumbled.I need to arrange it in order in power query editor or using DAX. Need your help to sort out the issue.

Input:

IDNames
123AB(123)
125CA(125)
156|256GH(256)|HR(156)
158|258|658OP(658)|AGM(258)|VP(158)
489|894CO(489)|CDF(894)
256JA(256)
785|987|258PAT(987)|PA(258)|SA(785)

 

Expected output

IDNames
123AB(123)
125CA(125)
156|256HR(156)|GH(256)
158|258|658VP(158)|AGM(258)|OP(658)
489|894CO(489)|CDF(894)
256JA(256)
785|987|258SA(785)|PAT(987)|PA(258)

 

Regards,

Harsha

2 REPLIES 2
slorin
Super User
Super User

Another solution with Table.ReplaceValue

 

= Table.ReplaceValue(PrevStep,each [ID],each [Names],(a, b, c)=> 
Text.Combine(
List.Sort(
Text.Split(c,"|"),
(x,y) =>
Value.Compare(
List.PositionOf(Text.Split(b, "|"), Text.BetweenDelimiters(x, "(", ")")),
List.PositionOf(Text.Split(b, "|"), Text.BetweenDelimiters(y, "(", ")"))
)
),
"|"
),
{"Names"})

Stéphane 

slorin
Super User
Super User

Hi,

 

 

let 
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NY1BDoMwDAT/kpMtcYHi4BxdKkCVEFFb9YL4iR/fDaG39exove+h7W6hCXYnBA5HU4iAjAYiF5HonUTQeSEE9uVFgP9W0apHURhbJgR2m1eoCN8MVavaa3JNfZnfCAf7+JgIpNb1x9POHycZVDzpUPbRZPsQLvZsdfttBAPq8QM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Names = _t]),
Fn_Sort = (Text1 as text, Text2 as text) as text=>
Text.Combine(
List.Sort(
Text.Split(Text2,"|"),
(x,y) =>
Value.Compare(
Text.PositionOf(Text1,Text.BetweenDelimiters(x, "(", ")")),
Text.PositionOf(Text1,Text.BetweenDelimiters(y, "(", ")"))
)
),
"|"
),
Sort = Table.AddColumn(Source, "Names_Sort", each Fn_Sort([ID], [Names]))
in
Sort

 Stéphane

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.