Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Regex with R Script

Hi,

I have a table containing Postal code and the regex pattern this postal code should follow to be correct.

What I want is a new column saying if the Postal code is matching the Pattern provided in the same row or now. With a simple TRUE/FALSE statement.

Currently I have tested this script in "R Script":

 

 

isMatch <- function(x,y) {grepl(y, as.character(x), ignore.case=TRUE)}
return <- within(dataset,{Flag=isMatch(dataset$Zip, dataset$Pattern)})

 

 

But as you can see, none of the records are matching.

jimmycederhag_0-1617177444998.png

Any suggestion on how to do this would be very helpful. Don't have to be in R Script 🙂

I will have a full table of 200k Postal codes coming up soon.

Thanks!

4 REPLIES 4
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

You can refer these two articles which introduce regular expression in details in power query, hopes it could help.

  1. Using Regular Expressions(RegEx) in Power BI 
  2. Power BI and Regular Expressions 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi,

Thanks, but these are reffering to manually input of the pattern. This is working if you are focusing on only a few patterns, not when you have 200+ patterns. 😞 

amitchandak
Super User
Super User

@Anonymous , refer if this power query M code can help

https://www.excel-university.com/power-query-and-zip-code-formatting/

 

Also check - https://www.youtube.com/watch?v=jCsA9e4BRdw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi,

Thanks, but this is not what I was after.

I am not after to format the Postal codes, I want to check if they are in the correct format according to Universal Postal Union.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors