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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
WorkHard_
Frequent Visitor

If statement doesn't recognize column in Power Query

I'm trying to extract the text from a column using the following 2 scenarios:
If column contains "/" then extract the remaining word after "/".
If column contains "()" extract the word from the last parantheses.
If I test each condition separately, it works as expected but I'm unable to join these 2 conditions into a single statement with a if/else/then statement.

What am I missing?


  #"Transform Values" = Table.TransformColumns(#"Duplicated Column", {{"ExtractedTranform", if each Text.Contains([Column1],"/") then each Text.AfterDelimiter(_, "/") else each Text.BetweenDelimiters(_, "(", ")", {0, RelativePosition.FromEnd}, 0), type text}} )

Expression.Error: We cannot apply field access to the type Text.


1 ACCEPTED SOLUTION
samratpbi
Super User
Super User

Hi, I am able to achieve using Split Column and some M query.

As you can see, Col1 was initial column. Col2 and Custom are intermediate columns and 4th one is the final column.
Source:

samratpbi_1-1747329121382.png

 

samratpbi_0-1747328915340.png

Below is the M Query:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjNyclXCMlILUpVitUB8fXRBUB8DbCAplJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"/"}, QuoteStyle.Csv, true), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Text.BetweenDelimiters([Column1.1],"(",")")),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Formatted", each if [Column1.2] <> null then [Column1.2] else if [Custom] <> "" then [Custom] else [Column1.1])
in
#"Added Conditional Column"

 

If this helps to resolve your problem, then please mark it as solution, thanks

Samrat

View solution in original post

1 REPLY 1
samratpbi
Super User
Super User

Hi, I am able to achieve using Split Column and some M query.

As you can see, Col1 was initial column. Col2 and Custom are intermediate columns and 4th one is the final column.
Source:

samratpbi_1-1747329121382.png

 

samratpbi_0-1747328915340.png

Below is the M Query:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kjNyclXCMlILUpVitUB8fXRBUB8DbCAplJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column1", Splitter.SplitTextByEachDelimiter({"/"}, QuoteStyle.Csv, true), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each Text.BetweenDelimiters([Column1.1],"(",")")),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Formatted", each if [Column1.2] <> null then [Column1.2] else if [Custom] <> "" then [Custom] else [Column1.1])
in
#"Added Conditional Column"

 

If this helps to resolve your problem, then please mark it as solution, thanks

Samrat

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.