Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone,
I have a dataset of hours worked by some users that is structured in this format
I woul like to transform it in this format
What kind of PowerQuery operations do I have to perform to get this result?
Thanks
Solved! Go to Solution.
Select all the Day columns and Unpivot them.
Select the Type column and Pivot it using the newly created Value column as the Value,
Split the Day column by the left 3 characters. Tidy up the columns by removing the ones you don't want and renaming the ones that need it.
I followed @HotChilli's instructions and I believe I got the exact result after I unpivoted the Day columns and then Pivoted the Type column using Value. Attached PBIX, here is the query code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRCsnPBZLh+UXZQMoCBcfqoCpyKkpNBKkyBGIjKG2IoSo4Mzk7L7W4GMg0QMEghSamZkC2V2pRUSXCVnMkW82xKEO21xDFXlR1uG2OBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [WorkedID = _t, Name = _t, Type = _t, Day1 = _t, Day2 = _t, Day3 = _t, Day4 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"WorkedID", Int64.Type}, {"Name", type text}, {"Type", type text}, {"Day1", Int64.Type}, {"Day2", Int64.Type}, {"Day3", Int64.Type}, {"Day4", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"WorkedID", "Name", "Type"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Type]), "Type", "Value", List.Sum)
in
#"Pivoted Column"
Select all the Day columns and Unpivot them.
Select the Type column and Pivot it using the newly created Value column as the Value,
Split the Day column by the left 3 characters. Tidy up the columns by removing the ones you don't want and renaming the ones that need it.
I followed @HotChilli's instructions and I believe I got the exact result after I unpivoted the Day columns and then Pivoted the Type column using Value. Attached PBIX, here is the query code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRCsnPBZLh+UXZQMoCBcfqoCpyKkpNBKkyBGIjKG2IoSo4Mzk7L7W4GMg0QMEghSamZkC2V2pRUSXCVnMkW82xKEO21xDFXlR1uG2OBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [WorkedID = _t, Name = _t, Type = _t, Day1 = _t, Day2 = _t, Day3 = _t, Day4 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"WorkedID", Int64.Type}, {"Name", type text}, {"Type", type text}, {"Day1", Int64.Type}, {"Day2", Int64.Type}, {"Day3", Int64.Type}, {"Day4", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"WorkedID", "Name", "Type"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Type]), "Type", "Value", List.Sum)
in
#"Pivoted Column"
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |