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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
I have a column BUSINESS_RULE_REF in a merged Power BI table that contains values like this:
105_AL_Subgroup_CIRCE_Consistency.
Each token between the underscores can be of a different length, I need the text between the first 2 underscores (AL in the example above).
Solved! Go to Solution.
Hi @allondon,
The fourth argument (not_found_value
) is optional. Using -1
is fine, but if the first underscore doesn’t exist, SEARCH
will return -1
, which breaks the second search.
Try below DAX
Category =
VAR TextValue = TRIM( 'Append ALL'[BUSINESS_RULE_REF] ) -- ensure text
VAR FirstUnderscore = SEARCH("_", TextValue, 1, 0) -- 0 if not found
VAR SecondUnderscore =
IF(
FirstUnderscore > 0,
SEARCH("_", TextValue, FirstUnderscore + 1, 0),
0
)
RETURN
IF(
FirstUnderscore > 0 && SecondUnderscore > FirstUnderscore,
MID(
TextValue,
FirstUnderscore + 1,
SecondUnderscore - FirstUnderscore - 1
),
BLANK()
)
🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!
The solution proivided by grazitti_sapna worked, though I'm still trying to understand how TRIM made the difference. Thanks everyone, I'll try other suggestions as well.
It worked, thanks! Now I need to understand why 🙂
and this code try
Category =
VAR _FirstUnderscore =SUBSTITUTE( SUBSTITUTE(
SUBSTITUTE('Append ALL'[BUSINESS_RULE_REF],"_","|"),"||","|"),"||","|")
VAR _ST = PATHITEM(_FirstUnderscore,2,TEXT)
RETURN
_ST
Category = //Try SUBSTITUTE()with PATHITEM() might help you
PATHITEM(SUBSTITUTE('Append ALL'[BUSINESS_RULE_REF], "_", "|"), 2)
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
try this code
Hi @allondon,
The fourth argument (not_found_value
) is optional. Using -1
is fine, but if the first underscore doesn’t exist, SEARCH
will return -1
, which breaks the second search.
Try below DAX
Category =
VAR TextValue = TRIM( 'Append ALL'[BUSINESS_RULE_REF] ) -- ensure text
VAR FirstUnderscore = SEARCH("_", TextValue, 1, 0) -- 0 if not found
VAR SecondUnderscore =
IF(
FirstUnderscore > 0,
SEARCH("_", TextValue, FirstUnderscore + 1, 0),
0
)
RETURN
IF(
FirstUnderscore > 0 && SecondUnderscore > FirstUnderscore,
MID(
TextValue,
FirstUnderscore + 1,
SecondUnderscore - FirstUnderscore - 1
),
BLANK()
)
🌟 I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
💡 Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
🎖 As a proud SuperUser and Microsoft Partner, we’re here to empower your data journey and the Power BI Community at large.
🔗 Curious to explore more? [Discover here].
Let’s keep building smarter solutions together!
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.