Forum Discussion

AFra's avatar
AFra
Icon for Helper III rankHelper III
6 years ago
Solved

Table transformation : columns become lines

Hi there, 

 

I have a 50.000 lines table with 23 columns such as : 

IDability Aability Bability C ability D
123451 1 
123461111
12347 1  

 

I'd like to transform this table so that I only have 3 columns : ID,ability, Available. The final result shoud be : 

IDAbilityAvailable
12345A1
12345B 
12345C1
12345D 
12346A1
12346B1
12346C1
12346D1
12347A 
12347B1
12347C 
12347D 

 

Is there a way to do this easily in powerbi? How? : ) 

Thanks in advance, 

Ana 

  • AFra,

     

    In Power Query, click on the ID column, and select Transform --> Unpivot Other Columns. Then rename the columns as desired.

     

     

2 Replies

  • AFra,

     

    In Power Query, click on the ID column, and select Transform --> Unpivot Other Columns. Then rename the columns as desired.

     

     

  • AFra 

    Paste the below code in a blank query in Power Query and follow the steps

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjFV0lEyBGIFOB2rA5Exg4ogMEzGHEU9WE8sAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"ability A" = _t, #"ability B" = _t, #"ability C " = _t, #"ability D" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
        #"Trimmed Text" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Attribute", Text.Trim, type text}}),
        #"Extracted Last Characters" = Table.TransformColumns(#"Trimmed Text", {{"Attribute", each Text.End(_, 1), type text}}),
        #"Renamed Columns" = Table.RenameColumns(#"Extracted Last Characters",{{"Attribute", "Ability"}, {"Value", "Avilable"}})
    in
        #"Renamed Columns"

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn