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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
MarcusR1
Helper II
Helper II

Using Python Regex to look for values in column

I'm trying to add a column called ofInterest select postcodes that match RG, OX & SA, the column would contain a 1 if the match is found, or 0 if not found.
My code is:

 

import pandas as pd
import re
dataset["ofInterest"] = dataset["RegAddress.PostCode"].re.search("[SRO][AGX][0-9]")

 

I'm sure I've got this all wrong because I have very little experience of Python (I know REGEX quite well) - can anybody help me?

6 REPLIES 6
Anonymous
Not applicable

Hi @MarcusR1 ,

 

Has your problem been solved?If the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.

 

Best Regards,

Neeko Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

Hi Neeko, unfortunately your solution doesn't work as REGEX becasue I need to look for any of the letters follwoed by a number (regexz /[SRO][AGX][0-9]/) but your suggestion doesn't do that.
all the best, Marcus

Anonymous
Not applicable

Hi @MarcusR1 ,

 

I'm sorry I can't understand your needs, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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 @MarcusR1 ,

According to your description, here are my steps you can follow as a solution.

(1)This is my test data. 

Table:

vtangjiemsft_0-1665998914636.png

Table(2):

vtangjiemsft_1-1665998936718.png

And the relationships between tables:

vtangjiemsft_2-1665998989060.png

(2)We can create a measure.

 

ofInterest = var _t = {"OX","RG","SA"} return IF( MAX('Table'[Type]) in _t , 1 ,0)

 

(3)Then the result is as follows.

vtangjiemsft_3-1665999064708.png

Please refer to the following documents that may be helpful:

Using regular expressions in power bi desktop - Microsoft Power BI Community

Regular expressions in Power Query – Q-stat

 

Best Regards,

Neeko Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

MarcusR1
Helper II
Helper II

Thanks Amit, I have posted it on the Python forum. I think it's still relevant here though, because the Table/Column structure is relevant to PowerBI, and hopefully if I find a solution it will help other PowerBI users.
As an aside, it would be great if PowerBI supported REGEX in DAX or PowerQuery 😉

amitchandak
Super User
Super User

@MarcusR1 , I would advice to ask this question on Python forum

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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.