Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I'm trying to create a new column in a table using the some of the data from another existing column if it matches a pattern. I'm playing around with LEFT and SEARCH, but can't get it to work.
Data Example:
If the data contains any OPC-* value, I'd like to put that, just the OPC-* in to a new column, i.e. the full OPC-<number> string.
Thank you
Solved! Go to Solution.
oh , im not sure i couldnt find an effiecent solution
Result 3 =
VAR StartPos = SEARCH("OPC-", [Existing Column], 1, LEN([Existing Column])) + 4
VAR TempString = MID([Existing Column], StartPos, 15) -- Assuming maximum length of OPC- string is 15
VAR NumberString =
CONCATENATEX(
FILTER(
GENERATESERIES(1, LEN(TempString)),
IFERROR(ISNUMBER(SEARCH(MID(TempString, [Value], 1), "0123456789")), FALSE)
),
MID(TempString, [Value], 1),
""
)
RETURN "OPC-" & NumberString
The following expression may work. It assumes OPC-### is directly followed by a space and returns a blank if OPC is not found in the text string.
OPC Value =
//Starting position of OPC in text string
VAR _opcStart = FIND("OPC", 'Table'[Data Column], 1, LEN('Table'[Data Column])+1)
//Position of the space following the OPC start position
VAR _opcEnd = FIND(" ", 'Table'[Data Column], _opcStart, LEN('Table'[Data Column])+1)
//Length of OPC-#####
VAR _opcLength = _opcEnd - _opcStart
RETURN
// Using MID allows for defining a starting position within the string (_opcStart) and a number of characters (_opcLength)
MID(
'Table'[Data Column],
_opcStart,
_opcLength
)
Existing Column | New Column |
| OPC-123456 |
| OPC-234567 |
| OPC-3456789 |
So if existing column has an OPC-<value> in it, I'd like to extract that OPC value in to a new column.
Many thanks
oh , im not sure i couldnt find an effiecent solution
Result 3 =
VAR StartPos = SEARCH("OPC-", [Existing Column], 1, LEN([Existing Column])) + 4
VAR TempString = MID([Existing Column], StartPos, 15) -- Assuming maximum length of OPC- string is 15
VAR NumberString =
CONCATENATEX(
FILTER(
GENERATESERIES(1, LEN(TempString)),
IFERROR(ISNUMBER(SEARCH(MID(TempString, [Value], 1), "0123456789")), FALSE)
),
MID(TempString, [Value], 1),
""
)
RETURN "OPC-" & NumberString
have you tried using the containstring function
if( containsstring([your column],"OPC") , "OPC")
so you need the full value from it?
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
10 | |
6 |