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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ValeriaBreve
Post Patron
Post Patron

String substraction from another string

Hello,

I have a table as per below:

 

MainCategoryCategory 2Final
AApples=PearsPears,Raisin,AppleRaisin
BRedYellow,Green,RedYellow,Green
CSeven=Five=SixOne,Two,Three,Four,SevenOne,Two,Three,Four

 

The Final table is what I need to achieve, so I need to substract each string in "Category" (between "=")  from the Category 2 if they are present.

 

Can you please h elp me? I am at a loss for ideas.

 

Thanks!

Kind regards

Valeria

 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @ValeriaBreve, you made a mistake probably, so I've edited your sample data a bit

dufoq3_0-1711630166098.png

 

Result

dufoq3_2-1711630253946.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("HYq7CoAwFEP/5c75hQ4q6Kioi5QOggELpZWKj8/32iUh58RaqQRSHUegGbjmU1dpjKs/fURR4mClVjVy01wYQnrQZTLiR79uVEy8GU3rb5rJvwr6SMxPwrzrF226MspHnPsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Main = _t, Category = _t, #"Category 2" = _t]),
    Ad_Final = Table.AddColumn(Source, "Final", each 
        [ a = Text.Split([Category], "="),
          b = Splitter.SplitTextByAnyDelimiter(a)([Category 2]),
          c = Text.Combine(List.Select(List.Transform(b, (x)=> Text.Trim(x, {" ", ","})), (y)=> not List.Contains({"", null},y)))
        ][c], type text)
in
    Ad_Final

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

4 REPLIES 4
dufoq3
Super User
Super User

Hi @ValeriaBreve, you made a mistake probably, so I've edited your sample data a bit

dufoq3_0-1711630166098.png

 

Result

dufoq3_2-1711630253946.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("HYq7CoAwFEP/5c75hQ4q6Kioi5QOggELpZWKj8/32iUh58RaqQRSHUegGbjmU1dpjKs/fURR4mClVjVy01wYQnrQZTLiR79uVEy8GU3rb5rJvwr6SMxPwrzrF226MspHnPsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Main = _t, Category = _t, #"Category 2" = _t]),
    Ad_Final = Table.AddColumn(Source, "Final", each 
        [ a = Text.Split([Category], "="),
          b = Splitter.SplitTextByAnyDelimiter(a)([Category 2]),
          c = Text.Combine(List.Select(List.Transform(b, (x)=> Text.Trim(x, {" ", ","})), (y)=> not List.Contains({"", null},y)))
        ][c], type text)
in
    Ad_Final

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Thanks @dufoq3 ! Yes you are right I made a spelling msitake in the data - sorry about that! And your solution works very well. Thanks! 🙂 

You're welcome Valeria.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

ValeriaBreve
Post Patron
Post Patron

OK I think I got there...

= Table.AddColumn(#"Changed Type", "No_Match",
each
List.RemoveMatchingItems(
Text.Split([Category 2],","),
Text.Split([Category],"=")
)
)

 

But I am opne to any other suggestions 🙂

Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors