Hi @Seth4040 ,
To extract the account number using DAX within Power BI, you can create a calculated column that isolates the numeric pattern in the format of XXXXXXXX-X (i.e., 7 to 8 digits, a hyphen, and a single digit). This solution assumes that the account number consistently follows that structure and appears somewhere within the text string, possibly surrounded by additional characters.
You may use the following DAX expression for the calculated column:
Extracted Account Number =
VAR TextString = [Vendor Invoice]
VAR HyphenPos = SEARCH("-", TextString, 1, -1)
VAR StartPos =
IF(
HyphenPos >= 8,
HyphenPos - 8,
1
)
VAR Extracted = MID(TextString, StartPos, 10)
RETURN
IF(
ISNUMBER(VALUE(LEFT(Extracted, 1))),
Extracted,
BLANK()
)
This formula identifies the position of the hyphen within the string, calculates the appropriate starting point for extraction by assuming 8 characters precede the hyphen, and then extracts a 10-character substring. It includes a basic validation to ensure that the extracted string begins with a numeric character. If the pattern varies more significantly, or if a higher level of precision is required, it would be advisable to handle this logic in Power Query, where text manipulation capabilities are more advanced.
Best regards,