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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Conditional Left Parse

I am new to Power BI and need some help. I need to parse the left part of the column before the (-) but there are several fields where there is no dash. In these cases, I want it to parse the left part of the column before the (.) and if there is neither, I want it to give me the entire field. Any suggestions on how I can accomplish that?

 

Sample Data:

 

Capture.PNG

 

 

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

You didn't mention if you want the result in the same column or in a new column.

 

The query below includes both alternatives.

 

let
    Source = #table(type table[PART_ID = text],{{"12-3983.98u"},{"897.yfdwhv"},{"jhjkkjygw"}}),

    Added = Table.AddColumn(Source, "ParsedPart", each if Text.Contains([PART_ID],"-") then Text.BeforeDelimiter([PART_ID],"-") else Text.BeforeDelimiter([PART_ID],".")),

    Transformed = Table.TransformColumns(Added,{{"PART_ID", each if Text.Contains(_,"-") then Text.BeforeDelimiter(_,"-") else Text.BeforeDelimiter(_,".")}})
in
    Transformed

 

This is how step "Added" looks like in the Query Editor with the popup for adding a custom column:

 

Conditional parse.png

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

You didn't mention if you want the result in the same column or in a new column.

 

The query below includes both alternatives.

 

let
    Source = #table(type table[PART_ID = text],{{"12-3983.98u"},{"897.yfdwhv"},{"jhjkkjygw"}}),

    Added = Table.AddColumn(Source, "ParsedPart", each if Text.Contains([PART_ID],"-") then Text.BeforeDelimiter([PART_ID],"-") else Text.BeforeDelimiter([PART_ID],".")),

    Transformed = Table.TransformColumns(Added,{{"PART_ID", each if Text.Contains(_,"-") then Text.BeforeDelimiter(_,"-") else Text.BeforeDelimiter(_,".")}})
in
    Transformed

 

This is how step "Added" looks like in the Query Editor with the popup for adding a custom column:

 

Conditional parse.png

Specializing in Power Query Formula Language (M)
Anonymous
Not applicable

This is perfect! Thank you so much. I wanted them in the same column and the second options works great. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors