Forum Discussion
Extract Address from Cell Text
Updated a bit
as
let
Source = Excel.CurrentWorkbook(){[Name="source"]}[Content],
quadrants = {" NW", " NE", " SW", " SE", " N", " E", " S", " W"},
fn = (str as text, add as text) =>
[
position = List.Max(
List.Transform(
quadrants,
(q) => [ p=Text.PositionOf(
str,
q & add,
Occurrence.Last,
Comparer.OrdinalIgnoreCase
),
e = if p < 0 then p else p + Text.Length(q)
][e]
)
),
length = if position < 0
then Text.Length(str)
else position
][length],
GetAddress = Table.AddColumn(
Source,
"Address",
each [
sepMid = fn([Text], " "),
sep = fn([Text], "" ),
sepEnd = List.Min({ sepMid, sep }),
address = Text.Start( [Text], sepEnd)
][address]
)
in
GetAddress
The Excel file isn't actually the source data and allowed me an easier way to see the data as of right now.
Source: Oracle
Navigation: SYNERGY{[Name="WORK_ORDER"]}
Column (with address): [WORK_DESC]
I am not strong at querying and am mistyping something that is leading to errors:
Source = Oracle.Database("Oracle",SYNERGY{[Name="WORK_ORDER"]}[WORK_DESC]),
Any further assistance is greatly appreciated, and if you need more information, please let me know.
- peiyezhuOct 11, 2024Bronze Contributorhttps://www.oracletutorial.com/oracle-string-functions/oracle-regexp_like/
oracle support regular expression.
You can try it- SergeiBaklanOct 12, 2024Diamond Contributor
Could you suggest regex pattern for such case?
- peiyezhuOct 12, 2024Bronze Contributor
OK
Because I have no ORACLE environment.
I use sqlite for example.
select *,regexp2('^.*\b(NW|NE|SW|SE|N|S|E|W|Ave)\b',f01)
f02 from Sheet1;
Oracle extract:
https://www.oracletutorial.com/oracle-string-functions/oracle-regexp_substr/
- SergeiBaklanOct 11, 2024Diamond Contributor
Sorry, I have no experience with Oracle. Just in case, here Power Query Oracle database connector - Power Query | Microsoft Learn is how to configure connection.
- RecycleBin_RobOct 11, 2024Copper Contributor
Hi, Thanks, I'll set up the Oracle at a later date. Ideally, I can get the Excel working first. I'm still running into a few issues.
I added a new Custom Column (Address) and inserted the coding you provided to my Excel sheet.
When I click on expand (in the column header), I get an error.
When I click on table and try to expand the address, I get an error.
Anymore insight you can provide? Thanks!
- SergeiBaklanOct 11, 2024Diamond Contributor
Let assume you have have couple of tables received from Oracle, I imitate them as
Related queries are
Let put function which calculates address length into separate query fnAddressLength
(str as text, add as text) => let quadrants = {" NW", " NE", " SW", " SE", " N", " E", " S", " W"}, position = List.Max( List.Transform( quadrants, (q) => [ p = Text.PositionOf( str, q & add, Occurrence.Last, Comparer.OrdinalIgnoreCase ), e = if p < 0 then p else p + Text.Length(q) ][e] ) ), length = if position < 0 then Text.Length(str) else position in lengthFinally we merge first two tables from Oracle and from the field Description extract Address
let Source = Table.NestedJoin( SV_WORK_ORDER, {"Customer ID"}, Customer, {"Customer ID"}, "Customer", JoinKind.LeftOuter), ExpandCustomer = Table.ExpandTableColumn( Source, "Customer", {"Description"}, {"Description"}), KeepColumns = Table.SelectColumns( ExpandCustomer, {"Work Order ID", "Description"}), GetAddress = Table.AddColumn( KeepColumns, "Address", each [ sepMid = fnAddressLength([Description], " "), sep = fnAddressLength([Description], "" ), sepEnd = List.Min({ sepMid, sep }), address = Text.Start( [Description], sepEnd) ][address] ), SelectColumns = Table.SelectColumns( GetAddress, {"Work Order ID", "Address"}) in SelectColumnswhich gives
Above is not optimized, just to illustrate an idea. All depends on what are your Oracle tables and which result you'd like to have.