Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Power Query - find option in text then select

Hi, this one might be ambitious but, I can't be the only person who's faced this challenge.

 

As a part of an address data cleansing exercise where I have values in a bunch of address fields that do not follow a proper pattern, I want to work my way from address_line_4 backwards to address_line_2 and see if any column contains a country name from list and where it does exist, then set country to that value.

 

Then, with or without country found, I want to do the same for city name from list and where it does exist, set city to that value AND for city, the corresponding country as well.

 

Then, (need to get a good data set for this one) I want to do the same for suburb name and where it does exist, set suburb to that value AND corresponding city and country.

 

Then I can include state in the mix as an additional so that if it sees VIC or NSW it might figure out its Australia. The issue with this one is VIC might be a part of a word and there's no gaurantee there will be a comma space VIC or comma VIC or space VIC no extra letters or spaces after, this one might be harder than the others.

 

A nice to have: The possibility of then also recognising the format of a street name line would be great but I think it might be way more complex, examples, understanding that both 99 STONNY BATTER ROAD and 11 HIGH STREET are both street street names with number and street type. The unit 5 in this case would be a pre-address line value like floor number, building name, etc.

 

Addresses are always a bit of a mission but, anything is better than the data I've got at the moment.

 

Addresses to be cleansed

address_line_1address_line_2address_line_3address_line_4
UNIT 599 STONNY BATTER ROAD,MINTOSYDNEY
5/15, VANDALUR ROADPADAPPAI, CHENNAITAMIL NADU?
11 HIGH STDUNEDIN??
79-81 SOUTH-CENTRE ROADMELBOUNE AIRPORT BUS, PARKTULLAMARINE, VIC?
15 ELDON STREETTAKAPUNANEW ZEALAND?

 

Country list

country_namecountry_code
AUSTRALIAAU
INDIAIN
NEW ZEALANDNZ

 

City list

city_namestatecountry_namecountry_code
SYDNEYNEW SOUTH WALESAUSTRALIAAU
CHENNAITAMIL NĀDUINDIAIN
MELBOURNEVICTORIAAUSTRALIAAU

 

End result

It wouldn't be a perfect address but at the very least, I should be able to resolve the city and country from the data set above to produce this:

address_linescitystatecountrycountry_code
UNIT 5, 99 STONNY BATTER ROAD, MINTOSYDNEYNEW SOUTH WALESAUSTRALIAAU
5/15, VANDALUR ROAD, PADAPPAICHENNAITAMIL NĀDUINDIAIN
79-81 SOUTH-CENTRE ROAD, MELBOURNE AIRPORT BIS, PARK, TULLARINEMELBOURNEVICTORIAAUSTRALIAAU
15 ELDON STREET, TAKAPUNA??NEW ZEALANDNZ

 

Note in my end result above, since I don't have the suburb list, I wouldn't have been able to resolve TAKAPUNA as a suburb or AUCKLAND that line simply say NEW ZEALAND in the address_line_3.

 

Thanks, Matt

  • Hi,

    I have used DAX to solve the question.  You may download my PBI file from here.

    Hope this helps.

      

4 Replies