Forum Discussion

francomaestri's avatar
francomaestri
Frequent Visitor
4 years ago
Solved

Normalization

Hi! I'm having problems normalizing some data. I want to create a new normalized table inside Power BI using the original one. The goal is that it is almos automatic, so someone can just add new d...
  • ValtteriN's avatar
    4 years ago

    Hi,

    You can unpivot the data in poowerquery.

    First select the columns:


    Now right-click a column header and select "unpivot columns"

    End result:


    I hope this helps to solve your issue and if it does consider accepting this as a solution and giving the post a thumbs up!

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi francomaestri , 

     

    Please follow ValtteriN  's suggest to use unpivot,below is the whole M syntax that you can paste in Advanced Editor:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8k0sSs5QMDIwMlDSUVIxNgGRRkYg0tRAKVYnWsmxoCgzB67AxAysAEyamoMV+CZWwqVNwTqNwWwzQ6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Category A" = _t, #"Category B " = _t, #"Category C" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Category A", Currency.Type}, {"Category B ", Currency.Type}, {"Category C", Currency.Type}}),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Date"}, "Attribute", "Value"),
        #"Extracted Text Range" = Table.TransformColumns(#"Unpivoted Other Columns", {{"Attribute", each Text.Middle(_, 9, 1), type text}}),
        #"Renamed Columns" = Table.RenameColumns(#"Extracted Text Range",{{"Attribute", "Category"}, {"Value", "Price"}})
    in
        #"Renamed Columns"

     

    If you want to do it using DAX, since It is not allowed to use DAX to change the table structure, you could use UNION() to create a new table :

    NewTable = 
    UNION(
      SELECTCOLUMNS('Table', "Date",[Date], "Category", "A", "Price", [Category A]),
      SELECTCOLUMNS('Table', "Date",[Date], "Category", "B", "Price", [Category B]),
      SELECTCOLUMNS('Table', "Date",[Date], "Category", "C", "Price", [Category C]))

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.