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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Sathyabalan
Frequent Visitor

DAX To Extract Text between the Hyphen from a table column in Power Bi Service

Hi All,

 

I am trying to extract the text between the Hypen

 

#"Device Names" = Table.AddColumn(Source, "Device Name", each Text.BetweenDelimiters([Device Name], "-", "-"), type text)

 

Sathyabalan_0-1718348061303.png

 

Result should be like below wherever the text not between Hyphen then it should be 0 or null

 

Sathyabalan_2-1718348423394.png

 

Regards

Sathya

2 REPLIES 2
Smalfly
Responsive Resident
Responsive Resident

Hi @Sathyabalan ,

 

if you have a max occurence of 2 hyphens, you can try to first split you column on the right-most delimiter. And then split the left part based on the left-most identifier:

 

split column by delimiter.PNG

 

 

In the advaced editor, this becomes:

 

#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Original text", "Original text - Copy"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Original text - Copy", Splitter.SplitTextByEachDelimiter({"-"}, QuoteStyle.Csv, true), {"Original text - Copy.1", "Original text - Copy.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Original text - Copy.1", type text}, {"Original text - Copy.2", type text}}),
#"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Original text - Copy.1", Splitter.SplitTextByEachDelimiter({"-"}, QuoteStyle.Csv, false), {"Original text - Copy.1.1", "Original text - Copy.1.2"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Original text - Copy.1.1", type text}, {"Original text - Copy.1.2", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Original text - Copy.1.2", "Result"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",null,"0",Replacer.ReplaceValue,{"Result"}),
#"Reordered Columns" = Table.ReorderColumns(#"Replaced Value",{"Original text", "Result", "Original text - Copy.1.1", "Original text - Copy.2"})

 

Good luck!

Hi @Smalfly Good Day!

I am using Power Bi Service where this options not available in GUI and the Advanced Editor as well, so looking for a function to create an addtional column, even We found a way to it by running the below Dax Function

 

HotelCodeAll = VAR startPos = SEARCH("H", 'Device'[Device Name], 1, 0)
VAR result = IF(startPos > 0, MID('Device'[Device Name], startPos, 5), "0")
RETURN result
 
but if there are two H vaule in the device name then it extracted as H-H245, instead of H2456 if the device name is GH-H2456 that is why We thought of going with text delimiter dax function - 'Text.BetweenDelimiters' to extract between Hyphen, that will resolve the issue, I can do it in Power Bi Desktop using the sample from column example also, so looking for DAX function only to extrac between the Hyphen in Power Bi Service
 
Best Regards
Sathya

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.