Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I am not sure if this can be done in Power Query (I am using Power BI). I am looking to create some new rows based on the existing data. It's almost like doing a bit of an unpivot but to an existing column and appending some info. Here is the data I have:
EntityId | FieldId | FieldValue | FieldDate |
abc123 | 1234 | 1264207944 | 1/1/2010 |
abc123 | 1666 | 4326.43 | 1/1/2010 |
abc123 | 1235 | Low Risk | 1/1/2010 |
abc123 | 98756 | 789 | 1/1/2010 |
abc123 | 2456 | 2680 | 1/1/2010 |
Here is what I am trying to accomplish (in order to do some compares to the source system):
EntityId | FieldId | FieldValue |
abc123 | 1234 | 1264207944 |
abc123 | 1234_FieldDate | 1/1/2010 |
abc123 | 1666 | 4326.43 |
abc123 | 1666_FieldDate | 1/1/2010 |
abc123 | 1235 | Low Risk |
abc123 | 1235_FieldDate | 1/1/2010 |
abc123 | 98756 | 789 |
abc123 | 98756_FieldDate | 1/1/2010 |
abc123 | 2456 | 2680 |
abc123 | 2456_FieldDate | 1/1/2010 |
Can this be done in Power Query?
Solved! Go to Solution.
Hello @TbombToronto
whenever you have a logic, there is a way to make it work in power query. What you think of using an Unpivoting-function on your last two colums? You can try this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKNjQyVtJRApImYMrMxMjA3NIEzNE31DcyMDRQitVBVmlmZgakTIyNzPRMjHErMzI2BVI++eUKQZnF2TjVWVqYm4LMM7ewxKnGyASsxMjMwgBFTSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EntityId = _t, FieldId = _t, FieldValue = _t, FieldDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"EntityId", type text}, {"FieldId", Int64.Type}, {"FieldValue", type text}, {"FieldDate", type date}}, "en-US"),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"EntityId", "FieldId"}, "Attribute", "Value")
in
#"Unpivoted Columns"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hello @TbombToronto
whenever you have a logic, there is a way to make it work in power query. What you think of using an Unpivoting-function on your last two colums? You can try this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKNjQyVtJRApImYMrMxMjA3NIEzNE31DcyMDRQitVBVmlmZgakTIyNzPRMjHErMzI2BVI++eUKQZnF2TjVWVqYm4LMM7ewxKnGyASsxMjMwgBFTSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [EntityId = _t, FieldId = _t, FieldValue = _t, FieldDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"EntityId", type text}, {"FieldId", Int64.Type}, {"FieldValue", type text}, {"FieldDate", type date}}, "en-US"),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"EntityId", "FieldId"}, "Attribute", "Value")
in
#"Unpivoted Columns"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Thanks, that does get me halfway there. I guess once I am there, I can create a new column where I can derive what I ultimately need. If the fieldid = field value then use field id otherwise concatenate fieldid + attribute.
Hello
Exactly. The only thing you have to pay attention that you cannot concatenate numbers and text. Use text.from to get a text value from your numbers column.
All the best
Jimmy
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.