Forum Discussion

RahulPBI's avatar
RahulPBI
Helper I
6 years ago

Split or Trim Rows Based on Certain Criteria

Hi Experts

I have a few thousand rows of data in one column and now have a need to this data into seperate columns

Tried to split columns and even tried Format without much luck

 

Does anyone have a suggestion on how can i split my column based on certain criteria?

Format of coulmn example

 

LP53 C60.B 4W 70A 3K

SP53 R65.B 36L 24W 70A 4K

FT54 R.B 24L 48W/35A 3K

OC20 ABC.B 12 L 18W/70A 5K

 

Result I would like power query to split the above emaple and show in as below

 

Column 1Column2Column3Column4Column5Column6
LP53C60.B 4W70A3k
SP53R65.B36L24W70A4K
FT54R.B12L48W35A3K
OC20ABC.B12 L18W70A5K

 

My problem is there are diffrent many instances and some could have some data not there, like row one

How do I get the rows broken up and the about columns and if the criteria is n

 

 

6 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi RahulPBI 

     

    Try this,

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PctNCoAgEAbQq3y4jvJnxtqm0CahsMCFeP9rNFK0frxaVTrZIXo9BlDBrFe4XbWhqqtD9izgfIL9lF7dbiZkMUsJtJTJ8T+PaDXWEEWNRYIR7pWF2wM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Text = _t]),
        #"Added Custom" = Table.AddColumn( Source, "Custom", each 
            let 
                split = Text.SplitAny( [Text], " /"  ),
                xxx = [
                    column1 = 
                        List.Select( 
                            split, 
                            (i) =>     
                                List.Contains( { "A".."Z" }, Text.Start( i, 1 ) ) 
                                and List.Contains( { "0".."9" }, Text.End( i, 1 ) ) 
                        ){0},
                    column2 =
                        List.Select( 
                            split, 
                            (i) => Text.EndsWith( i, ".B" ) 
                        ){0},
                    column3 =
                        try List.Select( 
                            split, 
                            (i) => Text.EndsWith( i, "L" ) 
                        ){0} otherwise null,
                    column4 =
                        List.Select( 
                            split, 
                            (i) => Text.EndsWith( i, "W" ) 
                        ){0},
                    column5 =
                        List.Select( 
                            split, 
                            (i) => Text.EndsWith( i, "A" ) 
                        ){0},
                    column6 =
                        List.Select( 
                            split, 
                            (i) => Text.EndsWith( Text.Upper( i ), "K" ) 
                        ){0}
                ] 
                
            in xxx
    
          
        ),
        #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"column1", "column2", "column3", "column4", "column5", "column6"}, {"column1", "column2", "column3", "column4", "column5", "column6"})
    in
        #"Expanded Custom"

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    LinkedIn

     

    • RahulPBI's avatar
      RahulPBI
      Helper I

      Hi Mariusz

      Works very well and managed to incorporate it into my live pbix

      It done the splits how I had wanted, but I didn't realise and take into account some other kind of splits

      I have some variations and is it possible to split the below data? I have attached a test pbix file, hopefully that helps

       

       

       

      Should be split like below

      Column1Column2Column3Column4Column5Column6Column7
      FT54G50.BEAM36 LED36W350mA3KD
      FT54R.BEAM36 LED72W700mA4KMOTION
      FT53G50.BEAM24 LED24W350mA3K7P EM [DI/SC]
      MT32DY B65/6F+B65/6R12 LED12W350mA3KMOTION D M
      MT32ZG70.BEAM2X6 LED36W700mA3000K2C DAL
      RT32A60 BEAM24 LED72W700/1400mARGB/3000KDM
      FL54G70.BEAM24 LED48W700mA4KADV
      VL50G60.BEAM12 LED24W700mA4KNE 7D [DA/PE]
      VL50G70.BEAM12 LED24W700mA4KNM 7G [DL/PE] I.S
      FL50-S DYG65/18F+Z70/6F24 LED24W350mA4KNA 7D [DL/PE] I.S
      RS30Z6012 LED24W700mARGBW 3KDA
      TY15-AP  17W500mA3KGRND DA
      LS410E./M.BEAM2x 3 LED12W700mA3000KREMOTE
      OC220B.BEAMDRKLIGHT LED24W700mA3000KDALI
      AS220B.BEAM12 LED36W1050mA3000KCATRY DA SPAL Mk4
      AS220B.BEAM12 LED24W700mA3000KCATRY DM Mk3/4
      OR120B.BEAM6 LED12W700mA3000KREMOTE
      LC230M.BEAM12 LED12W350mA3000KFOOD 48V
      L230 [FP] FRM  52W1400mA4000KDALI
      FC26-CCM.BEAM36 LED144W350mARGBWDMX
      LC23-CC [ZP] ZOM SPT 12 LED48W300mARGBWDMX
      LC23-TX [FP] FRM 12 LED44W1300mA2700-6000KDALI

       

      Its a very messy data, but working on fixing the new extries

       

      Is it possible to acheive? Hopefully it is

       

      Regards