cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ajitk15 Frequent Visitor
Frequent Visitor

Column split by conditon

I have a requirement to extract/split data if value starts with P or QM to be 7 characters rest should be as-is, how it can be achived? help needed

As-is

PABCP01A

CSOMTO04

PPQRX01M

QM0888TA

ATLCTL01

to-be

PABCP01

CSOMTO04

PPQRX01

QM0888T

ATLCTL01

1 ACCEPTED SOLUTION

Accepted Solutions
Super User I
Super User I

Re: Column split by conditon

@ajitk15 -

Are you meaning that you have so many conditions for Text.StartsWith = "P" || "QM" || etc.?

 

If so, then you should include those requirements in your question.

 

Otherwise, you just need to add the logic from the last statment 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([#"As-is"], "P") then Text.RemoveRange([#"As-is"],7) else if Text.StartsWith([#"As-is"],"QM") then Text.RemoveRange([#"As-is"],7) else [#"As-is"])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Super User I
Super User I

Re: Column split by conditon

@ajitk15 -

This seems to work:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnB0cg4wMHRUitWJVnIO9vcN8TcwAXMCAgKDIgwMfcGcQF8DCwuLEIgyxxAf5xAfA0Ol2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"As-is" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"As-is", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([#"As-is"], "P") then Text.RemoveRange([#"As-is"],7) else if Text.StartsWith([#"As-is"],"QM") then Text.RemoveRange([#"As-is"],7) else [#"As-is"])
in
    #"Added Custom"




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
ajitk15 Frequent Visitor
Frequent Visitor

Re: Column split by conditon

ChrisMendoza i have many such values below is the sample

 

Super User I
Super User I

Re: Column split by conditon

@ajitk15 -

Are you meaning that you have so many conditions for Text.StartsWith = "P" || "QM" || etc.?

 

If so, then you should include those requirements in your question.

 

Otherwise, you just need to add the logic from the last statment 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([#"As-is"], "P") then Text.RemoveRange([#"As-is"],7) else if Text.StartsWith([#"As-is"],"QM") then Text.RemoveRange([#"As-is"],7) else [#"As-is"])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Community Support Team
Community Support Team

Re: Column split by conditon

Hi ajitk15, 

You could follow above ChrisMendoza's suggestions or simplify code by "Or " condition like below

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnB0cg4wMHRUitWJVnIO9vcN8TcwAXMCAgKDIgwMfcGcQF8DCwuLEIgyxxAf5xAfA0Ol2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"As-is" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"As-is", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([#"As-is"], "P") or Text.StartsWith([#"As-is"],"QM") then Text.RemoveRange([#"As-is"],7) else [#"As-is"])
in
    #"Added Custom"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors