Forum Discussion
Creating new rows based on previous rows
- 5 years ago
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.
- Jimmy8015 years agoCommunity Champion
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