Power Query: Only keep PO values

sscornav

Board Regular
Joined
Mar 20, 2010
Messages
125
This seems like it should be simple, but I am new to PQ and couldn't find it in the search.

I have a column with data like this:
PO123456
Accrual
Amortization for XYZ
PO234555
PO999999
Invoice 123

I would like to clear out all values that do not start with "PO". I don't want to filter the rows, I just want to clear the other values so I am left with PO number.

Thanks!
Steve
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I don't want to filter the rows, I just want to clear the other values so I am left with PO number
So you want to keep the other rows but replace them with what? Null?
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Result = Table.ReplaceValue(Source,"a","b",(x,y,z)=>if Text.Start(x,2)<> "PO" then null else x,{"Column1"})
in
    Result

Book2
CDEF
1Table2Query Output
2Column1Column1
3PO123456PO123456
4Accrual
5Amortization for XYZ
6PO234555PO234555
7PO999999PO999999
8Invoice 123
9
Sheet1
 
Upvote 0
That looks like what I need, but it looks like you are creating a new table. I just want to get rid of the values in my existing table.

Is there a way to do that?
 
Upvote 0
Power Query:
= Table.ReplaceValue(YourTableName,"a","b",(x,y,z)=>if Text.Start(x,2)<> "PO" then null else x,{"YourColumnName"})
 
Upvote 0
Solution
This will do too. Gordon's version will come in handy when you want to replace values in multiple columns

Power Query:
= Table.ReplaceValue(Source,each [Column1], each if Text.Start([Column1],2) <>"PO" then "" else _ ,Replacer.ReplaceText,{"Column1"})
 
Upvote 0
The marked solution has been changed with the answer post (post #5) in this thread as it will also help future readers.
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,063
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top