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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DAX - Extract text before second delimeter "-"

Hi,

 

I have a calculated column as below

CA-ORG-SDV-FRESZ

CA-OPN-SDR

CA-SRT-RZS-gSRE

OFFICE

OTHER

 

I would like to export the text before the second delimeter with DAX , the result would be like this :

CA-ORG

CA-OPN

CA-SRT

OFFICE

OTHER

 

Many thanks in advance.

Tg 

1 ACCEPTED SOLUTION
ChiragGarg2512
Solution Sage
Solution Sage

@Anonymous Try this calculated column
Column =
var _path = SUBSTITUTE('Table'[Column1], "-", "|")
var _litems = PATHITEM(_path, 1, TEXT)
var _litems1 = PATHITEM(_path, 2, TEXT)
var _value = if(_litems1 = "", _litems, _litems & "-" & _litems1)

return
_value

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Screenshot (34).png

ChiragGarg2512
Solution Sage
Solution Sage

@Anonymous Try this calculated column
Column =
var _path = SUBSTITUTE('Table'[Column1], "-", "|")
var _litems = PATHITEM(_path, 1, TEXT)
var _litems1 = PATHITEM(_path, 2, TEXT)
var _value = if(_litems1 = "", _litems, _litems & "-" & _litems1)

return
_value
Anonymous
Not applicable

Hi, this works but I have 1 case that didn't work 

 

CA-OPF_DFEYH

 

Result is always the same . 

Could you please advise ? 

Tg 

Anonymous
Not applicable

here is the dax query for Screenshot (34).png

johnbasha33
Super User
Super User

@Anonymous  use this measure and replace with your actual table name and column name
ExtractedText =
VAR FirstDelimiterPos = FIND("-", 'YourTable'[YourColumn], 1, LEN('YourTable'[YourColumn]))
VAR SecondDelimiterPos = FIND("-", 'YourTable'[YourColumn], FirstDelimiterPos + 1, LEN('YourTable'[YourColumn]))
VAR Length = SecondDelimiterPos - FirstDelimiterPos - 1
RETURN
IF(
SecondDelimiterPos > 0,
LEFT('YourTable'[YourColumn], SecondDelimiterPos - 1),
'YourTable'[YourColumn]
)

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

Anonymous
Not applicable

@johnbasha33 

This solution works well except the case CA-OPF_DFEYH

mh2587
Super User
Super User

 

TextBeforeSecondDelimiter = //Try this
VAR FirstDelimiterPosition = FIND("-", [Column], 1, LEN([Column]))
VAR SecondDelimiterPosition = FIND("-", [Column], FirstDelimiterPosition + 1, LEN([Column]))
RETURN LEFT([Column], SecondDelimiterPosition - 1)

 


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Anonymous
Not applicable

@mh2587 Thanks for your help, I got the message "An argument of the 'LEFT' function has the wrong data type or an invalid value."

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.