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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Katerina_SL
Helper II
Helper II

string values substraction

Hello everyone!
I would like to ask help with solving my task.
I have 1 column in power bi which contains string values.

Here the example 

Katerina_SL_0-1711112361934.png

In other words, 
I need to start from down and minus previous row.
For example,
row 1 = "Marek"
row 2 = "Marek, Marek, Jakub". The result will be "Marek, Marek, Jakub" - "Marek" = "Marek, Jakub"
row 4 = "Jakub, Marek, Jakub". The result will be "Jakub, Marek, Jakub" - "Marek, Jakub" (what we get as a result in row 1) = "Jakub"

 

Thank you in advance for any suggestiona and advices,
Ekaterina

1 REPLY 1
lbendlin
Super User
Super User

Your row number sequence is off for 13 and 15. Please clarify.

lbendlin_0-1711224255279.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJNLErNVorViVYygvF0FKCUV2J2aRJYzgQoB+ZhkTOHyYF5hgZAbkBiWX4OhGuMyjUFcoPz8xIhNhpAeToKEDIgtSS1CCIFchuYi0XOGCEHpYCOKsnMU4qNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Row = _t, Input = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Row", Int64.Type}, {"Input", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Result", each List.Accumulate({0..[Index]},"",(state,current)=>
let p = Text.PositionOf(#"Added Index"[Input]{current},state)
in if p=-1 then #"Added Index"[Input]{current} else Text.RemoveRange(#"Added Index"[Input]{current},p,Text.Length(state))),type text),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom",each [Result],each if Text.StartsWith([Result],", ") then Text.RemoveRange([Result],0,2) else [Result],Replacer.ReplaceValue,{"Result"})
in
    #"Replaced Value"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

 

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors
Top Kudoed Authors
Users online (2,340)