Forum Discussion

Steffen1's avatar
Steffen1
Frequent Visitor
3 years ago
Solved

Transforming Data from row to column

Dear Community,

 

I am looking for a solution to transform a value from a cell into a column, my source is looking as following: 

 

 

Now I would like to structure the data in columns only and get rid of the 3 header rows. 

 

However I need the data from the HEADER1 row. Therefore I would like to transfer the diffrent values from that row into columnĀ“s. 

 

Thank you very much for the support

 

Best Regards

 

Steffen

 

  • Steffen1 I did this:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lY9NCsJADIWvIl2Xkp+ZzGRZaMGFdaFYhNL7X8MMNtWKiF3kTRJevkmmqTr2bddfsKorgQCKxMFyhAawISC2ghUhpMZaVgxtf7MnWlAk08OSzbXDSjdxIUVZDN/jNcI/fe59IlNWEAkhQtmnG5eVGcoR17K8CkYGgZzK/+PZJORVbA6yiOZ/mcOGmdmZiVz2M08bpoIzJbjsZ943UDM6lNVlP5Q+qLieT+ryTp0f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t]),
        #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] = "12345678906644500" or [Column1] = "HEADER1")),
        #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Column10", each if [Column1] = "HEADER1" then [Column2] else null),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Column11", each if [Column1] = "HEADER1" then [Column3] else null),
        #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Column12", each if [Column1] = "HEADER1" then [Column4] else null),
        #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Column13", each if [Column1] = "HEADER1" then [Column5] else null),
        #"Filled Down" = Table.FillDown(#"Added Custom3",{"Column10", "Column11", "Column12", "Column13"}),
        #"Filtered Rows1" = Table.SelectRows(#"Filled Down", each ([Column1] = "12345678906644500"))
    in
        #"Filtered Rows1"

5 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi Steffen1 

    Can you share the input and expected output tables? At least the input table in text-tabular format so that its contents can be readily copied

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

  • Steffen1's avatar
    Steffen1
    Frequent Visitor

    Dear AlB , Greg_Deckler,

     

    thank you very much for your very fast replies, please find below the requested: 

     

    here the input: 

    HEADER160409123410.01.2023391047.0.0MAEU5252 252
    HEADER273123456       
    HEADER3        
    12345678906644500DV1234301S196153060876VN48484500086698
    12345678906644500DV1234301M196153060883VN72724500086698
    12345678906644500DV1234301L196153060890VN64644500086698
    12345678906644500DV1234301XL196153060906VN39394500086698
    12345678906644500DV12343012XL196153060913VN29294500086698

     

    here the desired outcome: 

     

    12345678906644500DV9742301S196153060876VN4848450008669860409123410.01.2023391047.0.0MAEU
    12345678906644500DV9742301M196153060883VN7272450008669860409123411.01.2023391047.0.1MAEU
    12345678906644500DV9742301L196153060890VN6464450008669860409123412.01.2023391047.0.2MAEU
    12345678906644500DV9742301XL196153060906VN3939450008669860409123413.01.2023391047.0.3MAEU
    12345678906644500DV97423012XL196153060913VN2929450008669860409123414.01.2023391047.0.4MAEU

     

    Best Regards

     

    Steffen

     

    • Greg_Deckler's avatar
      Greg_Deckler
      Community Champion

      Steffen1 I did this:

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lY9NCsJADIWvIl2Xkp+ZzGRZaMGFdaFYhNL7X8MMNtWKiF3kTRJevkmmqTr2bddfsKorgQCKxMFyhAawISC2ghUhpMZaVgxtf7MnWlAk08OSzbXDSjdxIUVZDN/jNcI/fe59IlNWEAkhQtmnG5eVGcoR17K8CkYGgZzK/+PZJORVbA6yiOZ/mcOGmdmZiVz2M08bpoIzJbjsZ943UDM6lNVlP5Q+qLieT+ryTp0f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t]),
          #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] = "12345678906644500" or [Column1] = "HEADER1")),
          #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Column10", each if [Column1] = "HEADER1" then [Column2] else null),
          #"Added Custom1" = Table.AddColumn(#"Added Custom", "Column11", each if [Column1] = "HEADER1" then [Column3] else null),
          #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Column12", each if [Column1] = "HEADER1" then [Column4] else null),
          #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Column13", each if [Column1] = "HEADER1" then [Column5] else null),
          #"Filled Down" = Table.FillDown(#"Added Custom3",{"Column10", "Column11", "Column12", "Column13"}),
          #"Filtered Rows1" = Table.SelectRows(#"Filled Down", each ([Column1] = "12345678906644500"))
      in
          #"Filtered Rows1"
      • Steffen1's avatar
        Steffen1
        Frequent Visitor

        Greg_Deckler,

         

        Oh, **bleep**,  this is a so easy solution, I guess I spend too much time thinking on it. 

         

        Thank you very much