March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
If I have a table like this:
How can I widen it into something like this:
Thank you for your help.
Solved! Go to Solution.
I actually ran into a similar problem yesterday. So first make sure this is the way you want to model it vs splitting up employees and tests. If this is what you actually need, here are the steps...you have two options:
Option A (easy but requires multiple tables)
Option B (more difficult but able to do with just one table)
The downside with both these solutions is if there is ever a Test D you will have to write that into the query.
Hi @Anonymous ,
Although the @PANDAmonium is a good solution this is a very complex way of making this work.
Based on the solution given on this blog post there is a much easier way of making this work:
[Test] & "," &[Attribute]
Check the full code below:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc/BDsIgDAbgVzE98xKOeJgHL9tt4YBYFxQ7w6aJb7+CnTGGxQNQkq/0p+tgb90VFDQ24Mhni+O02XKheV0spf1BYFRZVlwcGkEK7D2uUr3QhBQMbnpTHwJfd9R7Ioye+t8UNDzzgPDHV+XUq/4T6GajtOUGpNRft9855I9B4hTdMv+ETh4tMi3sjMfMXmDMDA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Job = _t, Test = _t, Status = _t, date1 = _t, Date2 = _t]), #"Unpivoted Columns1" = Table.UnpivotOtherColumns(Source, {"Employee", "Job", "Test"}, "Attribute", "Value"), #"Added Custom" = Table.AddColumn(#"Unpivoted Columns1", "Test_Column_Name", each [Test] & "," &[Attribute]), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Test", "Attribute"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Test_Column_Name]), "Test_Column_Name", "Value") in #"Pivoted Column"
Regards,
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsHi @Anonymous ,
Although the @PANDAmonium is a good solution this is a very complex way of making this work.
Based on the solution given on this blog post there is a much easier way of making this work:
[Test] & "," &[Attribute]
Check the full code below:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc/BDsIgDAbgVzE98xKOeJgHL9tt4YBYFxQ7w6aJb7+CnTGGxQNQkq/0p+tgb90VFDQ24Mhni+O02XKheV0spf1BYFRZVlwcGkEK7D2uUr3QhBQMbnpTHwJfd9R7Ioye+t8UNDzzgPDHV+XUq/4T6GajtOUGpNRft9855I9B4hTdMv+ETh4tMi3sjMfMXmDMDA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Job = _t, Test = _t, Status = _t, date1 = _t, Date2 = _t]), #"Unpivoted Columns1" = Table.UnpivotOtherColumns(Source, {"Employee", "Job", "Test"}, "Attribute", "Value"), #"Added Custom" = Table.AddColumn(#"Unpivoted Columns1", "Test_Column_Name", each [Test] & "," &[Attribute]), #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Test", "Attribute"}), #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Test_Column_Name]), "Test_Column_Name", "Value") in #"Pivoted Column"
Regards,
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsOh, cool. I had to try this for myself; I was hoping someone had a better solution.
Yeah, go with @MFelix solution. That is much cleaner and removes any issues of new tests.
I actually ran into a similar problem yesterday. So first make sure this is the way you want to model it vs splitting up employees and tests. If this is what you actually need, here are the steps...you have two options:
Option A (easy but requires multiple tables)
Option B (more difficult but able to do with just one table)
The downside with both these solutions is if there is ever a Test D you will have to write that into the query.
The multiple table scenario worked thank you!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
User | Count |
---|---|
90 | |
90 | |
83 | |
73 | |
49 |
User | Count |
---|---|
167 | |
149 | |
98 | |
73 | |
57 |