Home > Blockchain >  Excel - Power Query TrimStart With condition
Excel - Power Query TrimStart With condition

Time:01-10

I want to trim 2 chars. if it’s Start with “20”

Example: 20456 208899 123 366420

Result: 456 8899 123 366420

CodePudding user response:

You can test whether the text starts with "20", and if so, then return the text after "20":

if Text.StartsWith(Example, "20") then Text.AfterDelimiter(Example,"20") else Example

CodePudding user response:

I started with a basic text file that looks like this ...

Example
20456 208899 123 366420
20324 535435 654 533454
852 929492 583 283832

... and for transparency and to show you how I got through it, all steps are outlined below. I suspect this could be done in a more efficient manner but it does the job.

Step 1

Step 1

Step 2

Step 2

Step 3

Step 3

= Table.AddColumn(
#"Promoted Headers", 
"Result", 
each if Text.StartsWith([Example], "20") then Text.Middle([Example], 2) else [Example])

Step 4

Step 4

Step 5 (Result)

Step 5

  •  Tags:  
  • Related