Forum Discussion

Ka4ra's avatar
Ka4ra
New Member
2 years ago
Solved

How to change data (pivot? Group?)

I want to change the data format.

 

Below is sample data. Data has a same ID, Value but Col1 to Col7 some have data and some do not.

I'm doing data transformation in Power BI, but I don't know what to do. 

 

DateIDVALUECol1Col2Col3Col4Col5Col6Col7
23-01-01 2:40 PMAAAAA320null225nullnullnullnull
23-01-01 2:40 PMAAAAA32015nullnullnull20nullnull
23-01-01 2:40 PMAAAAA320nullnullnull52nullnullnull
23-01-02 12:10 PMAVSV2491021null26nullnullnull
23-01-02 12:10 PMAVSV249nullnullnullnullnullnullnull
23-01-02 12:10 PMAVSV249nullnull0.1nullnullnullnull

 

 

I want to change the format data look like below.

I would like to put the data of each column matching the ID into one ID row for each column.

DateIDVALUECol1Col2Col3Col4Col5Col6Col7
23-01-01 2:40 PMAAAAA320152255220nullnull
23-01-02 12:10 PMAVSV24910210.126nullnullnull

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  Ka4ra ,

     

    Here are the steps you can follow:

    1. Create calculated table.

    Table2 =
    SUMMARIZE(
        'Table',[Date],[ID],[VALUE],
        "Co1",MAX('Table'[Col1]),
        "Co2",MAX('Table'[Col2]),
        "Co3",MAX('Table'[Col3]),
        "Co4",MAX('Table'[Col4]),
        "Co5",MAX('Table'[Col5]),
        "Co6",MAX('Table'[Col6]),
        "Co7",MAX('Table'[Col7]))

    2. Result:

     

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Ka4ra ,

     

    Here are the steps you can follow:

    1. Create calculated table.

    Table2 =
    SUMMARIZE(
        'Table',[Date],[ID],[VALUE],
        "Co1",MAX('Table'[Col1]),
        "Co2",MAX('Table'[Col2]),
        "Co3",MAX('Table'[Col3]),
        "Co4",MAX('Table'[Col4]),
        "Co5",MAX('Table'[Col5]),
        "Co6",MAX('Table'[Col6]),
        "Co7",MAX('Table'[Col7]))

    2. Result:

     

     

    Best Regards,

    Liu Yang

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

  • amustafa's avatar
    amustafa
    Solution Sage

    In Power Query, all you need to do is to Group By Date, ID and Value and do a SUM on rest of the columns. Here's a sample M Code. Adjust the source and let it run.

     

    let
    Source = Excel.Workbook(File.Contents("C:\tmp\Power BI Samples\Grouping Data\Group Data Sample.xlsx"), null, true),
    Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Date", type text}, {"ID", type text}, {"VALUE", Int64.Type}, {"Col1", Int64.Type}, {"Col2", Int64.Type}, {"Col3", type number}, {"Col4", Int64.Type}, {"Col5", Int64.Type}, {"Col6", type any}, {"Col7", type any}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "ID", "VALUE"}, {{"Col1", each List.Sum([Col1]), type nullable number}, {"Col2", each List.Sum([Col2]), type nullable number}, {"Col3", each List.Sum([Col3]), type nullable number}, {"Col4", each List.Sum([Col4]), type nullable number}, {"Col5", each List.Sum([Col5]), type nullable number}, {"Col6", each List.Sum([Col6]), type any}, {"Col7", each List.Sum([Col7]), type any}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Grouped Rows",{{"Col1", type number}, {"Col2", type number}, {"Col3", type number}, {"Col4", type number}, {"Col5", type number}, {"Col6", type number}, {"Col7", type number}})
    in
    #"Changed Type1"