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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register 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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.