Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.
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?
User | Count |
---|---|
9 | |
8 | |
6 | |
4 | |
3 |