Power Query Extract

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I need to exact any words that start with Q

If I use;
= Table.AddColumn(#"Renamed Columns", "Text Between Delimiters", each Text.BetweenDelimiters([Extract Q_Number], "Q", " "), type text)
it removes the "Q" because this say to extract between.

Is there a way to do this and keep the "Q"?

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
if Text.BetweenDelimiters([InternalRefNum], "Q", " ") = "" then "" else "Q" &Text.BetweenDelimiters([InternalRefNum], "Q", " ")

This works but if you have a different way, I would like to learn. Thanks
 
Upvote 0
Text.StartsWith ( string, "Q")?
 
Upvote 0
Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclQoLM1MzlYIyC9PLVIILE0tqlSK1YlWCizNTC1RKMhJTSxOBQu4JOYBpRMzc4AaUotLMvPzipViYwE=", BinaryEncoding.Base64), Compression.Deflate))),
    Result = Table.AddColumn(Source, "Q words", each Text.Combine(List.Select(Text.Split([Column1], " "), (x)=> Text.Upper(Text.Start(x,1)) = "Q"), ", "))
in
    Result
 
Upvote 0
Was without Excel before

Assuming data may look like below
Book1
C
2InternalRefNum
3n59545J-26940
4[67615j-31431
5i18817Q-73719
6H43547u-19019
7O32633j-21372
8w79989O-88946
9B73014X-91704
10q88163L-24254
11j87661g-45742
12C29617E-17256
13a70784k-15288
14Q92116e-88077
15R92323h-44607
16J20434a-77659
17b20201A-90581
18f94345K-68380
19s10736_-83270
20W92586d-99789
21\73345^-89845
22P29691F-97103
23s44986G-23326
24A74546v-44310
25Q74182j-13054
Sheet1

using this query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="RefNrs"]}[Content],
    Type_txt = Table.TransformColumnTypes(Source,{{"InternalRefNum", type text}}),
    Select_q_nrs = Table.SelectRows(Type_txt, each Text.StartsWith([InternalRefNum], "q", Comparer.OrdinalIgnoreCase))
in
    Select_q_nrs
returns
Book1
C
28InternalRefNum
29q88163L-24254
30Q92116e-88077
31Q74182j-13054
Sheet1


Following the idea by @JGordon11, there can more items in the field.
Book1
E
2InternalRefNum
3A45076v-30743 t77379l-11233 o42191L-80002 ]51075W-72440
4q88163L-24254 m72023a-66105 g63783g-68472 v58874D-49286
5a44397R-82559 \97110r-44940 [19987J-66245 B15419p-12519
6g42997\-10003 Z74920r-94253 w99519l-69687 k32702t-15909
7H58315O-93218 m36787c-99256 _31963s-25208 y92731t-38562
8V94042J-76924 m86742Q-77387 m87671b-82736 b61404H-51106
9Q74182j-13054 a89937B-55201 _84930a-29203 v48489S-84524
10`54687L-37310 J89867b-58165 g72969^-48930 M37511]-65751
11F76605P-58346 T88209q-35721 m38012E-41110 P83160t-54732
12[70328H-70280 Y80805i-27834 e61064_-59633 M93494Z-24855
13e77170D-70920 C13090o-84284 j37761U-14190 h66910s-67576
14A75437Q-52455 p86361_-17299 j60796u-51969 a21507Y-64797
15]80790G-98676 c97285]-90495 R17310L-66229 N93625Q-64548
16`72548W-90980 J30881J-52974 b88034x-65181 V77499^-27256
17b52351K-69098 k91870i-78299 y21525n-18323 v13027H-17546
18^54335T-36913 S28174^-54282 L20755S-50126 H10028a-49443
19h87069Q-89702 Q55454L-42935 F22540p-40426 a15579s-37492
20g29059b-41283 w63654]-80515 L85962t-89073 D80336w-26731
21]52072Z-10713 f40858M-49689 D47355p-43295 u65097]-75345
22q11207d-90922 b97088Q-39205 W98030r-84577 q82979q-39837
Sheet1

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="RefNrs_2"]}[Content],
    Type_txt = Table.TransformColumnTypes(Source,{{"InternalRefNum", type text}}),
    Select_q_nrs = List.RemoveNulls(List.TransformMany(Type_txt[InternalRefNum], (x) => Text.Split(x, " "), (x, y) => if Text.StartsWith(y, "q", Comparer.OrdinalIgnoreCase) then y else null ) )
in
    Select_q_nrs
Book1
E
28RefNrs_2
29q88163L-24254
30Q74182j-13054
31Q55454L-42935
32q11207d-90922
33q82979q-39837
Sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,223,391
Messages
6,171,817
Members
452,426
Latest member
cmachael

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