Forum Discussion

MagdoulinShams1's avatar
MagdoulinShams1
New Member
1 year ago
Solved

Power Query, Split Columns into Columns Conditinally

I have the below step code:

 

= if List.AnyTrue(List.Transform(#"Capitalized Each Word"[Delivery status], each Text.Contains(_, "/"))) then Table.SplitColumn(#"Capitalized Each Word", "Delivery status", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Status", "Count"}) else #"Capitalized Each Word"

 

What I am trying to do is to split column: Delivery status into columns: Status and Count, by delimeter " ", only if column: Delivery status contains "/", otherwise, do not proceed with the split.

 

It executes perfectly when if is TRUE, but it does not execute correctly when if is FALSE, it should not split, but it splits anyways.

 

What do I need to modify here?

4 Replies

  • Hi! It's ok - let the split happen on everything. Then, add a conditional column and do something similar to the below. You would say that if one column contains a /, return the value in column A, if it does not, return column B. 

     

    • MagdoulinShams1's avatar
      MagdoulinShams1
      New Member

      I hoped to reach the desired outcome in one step, but this is a good suggestion too.

  • Hi,

    Could you share some data to work with and show the expected result.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, MagdoulinShams1 

    Thanks for the reply form Ashish_Mathur and audreygerred. You can try to use the Split Column function directly.

     

     

    = Table.SplitColumn(#"Changed Type", "Delivery status", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Status", "Count"})

     

    Best Regards,
    Yang

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know.
    Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum