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
mrbajana
Helper III
Helper III

Convert Table Structure

Is posible in powerquery to convert this table 

 

From this table

Código

Empleado

Marcaciones

1

Alejandro

20/07/2018 8:00:00

1

Alejandro

20/07/2018 12:00:00

1

Alejandro

20/07/2018 13:00:00

1

Alejandro

20/07/2018 17:00:00

2

José

20/07/2018 8:00:00

2

José

20/07/2018 12:00:00

2

José

20/07/2018 13:00:00

2

José

20/07/2018 13:00:10

2

José

20/07/2018 17:00:00

 

To this table:

Código

Empleado

Fecha

Marcación 1

Marcación 2

Marcación 3

Marcación 4

Marcación 5

1

Alejandro

20/7/2018

8:00:00

12:00:00

13:00:00

17:00:00

 

2

José

20/7/2018

8:00:00

12:00:00

13:00:00

13:00:10

17:00:00

 

Thanks

Marco

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @mrbajana ,

 

Try this mcode:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLMSc1KzEspygeyjQz0Dcz1jQwMLRQsrAwMgEgpVgevMkMjItUZE6nOHEmdEVDOK7/48ErcTsOhBMVZuNQYE6vGEL8auJNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Código = _t, Empleado = _t, Marcaciones = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Código", Int64.Type}, {"Empleado", type text}, {"Marcaciones", type datetime}}),
#"Inserted Time" = Table.AddColumn(#"Changed Type", "Time", each DateTime.Time([Marcaciones]), type time),
#"Changed Type1" = Table.TransformColumnTypes(#"Inserted Time",{{"Marcaciones", type date}}),
#"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type1", {"Marcaciones"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Only Selected Columns", {"Código", "Empleado"}, {{"Rows", each
Table.CombineColumns(
Table.TransformColumnTypes(
Table.AddIndexColumn(_, "Index", 1,1), {{"Index", type text}}
),
{"Attribute", "Index"},
Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),
"Merged"
), type table [Código=number, Empleado=text, Time=time, Attribute=text, Value=date, Merged=text]}}),
#"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"Código", "Empleado", "Time", "Value", "Merged"}, {"Código", "Empleado", "Time", "Value", "Merged"}),
#"Pivoted Column" = Table.Pivot(#"Expanded Rows", List.Distinct(#"Expanded Rows"[Merged]), "Merged", "Time")
in
#"Pivoted Column"

 

Capture.PNG

 

 



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

Proud to be a Super User!



View solution in original post

1 REPLY 1
camargos88
Community Champion
Community Champion

Hi @mrbajana ,

 

Try this mcode:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXLMSc1KzEspygeyjQz0Dcz1jQwMLRQsrAwMgEgpVgevMkMjItUZE6nOHEmdEVDOK7/48ErcTsOhBMVZuNQYE6vGEL8auJNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Código = _t, Empleado = _t, Marcaciones = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Código", Int64.Type}, {"Empleado", type text}, {"Marcaciones", type datetime}}),
#"Inserted Time" = Table.AddColumn(#"Changed Type", "Time", each DateTime.Time([Marcaciones]), type time),
#"Changed Type1" = Table.TransformColumnTypes(#"Inserted Time",{{"Marcaciones", type date}}),
#"Unpivoted Only Selected Columns" = Table.Unpivot(#"Changed Type1", {"Marcaciones"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Only Selected Columns", {"Código", "Empleado"}, {{"Rows", each
Table.CombineColumns(
Table.TransformColumnTypes(
Table.AddIndexColumn(_, "Index", 1,1), {{"Index", type text}}
),
{"Attribute", "Index"},
Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),
"Merged"
), type table [Código=number, Empleado=text, Time=time, Attribute=text, Value=date, Merged=text]}}),
#"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Rows"}),
#"Expanded Rows" = Table.ExpandTableColumn(#"Removed Other Columns", "Rows", {"Código", "Empleado", "Time", "Value", "Merged"}, {"Código", "Empleado", "Time", "Value", "Merged"}),
#"Pivoted Column" = Table.Pivot(#"Expanded Rows", List.Distinct(#"Expanded Rows"[Merged]), "Merged", "Time")
in
#"Pivoted Column"

 

Capture.PNG

 

 



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

Proud to be a Super User!



Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

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.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors