Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Ka4ra
New Member

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

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

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:

vyangliumsft_0-1705642921606.png

 

 

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

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

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:

vyangliumsft_0-1705642921606.png

 

 

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
Super User
Super User

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"

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.