Forum Discussion

TbombToronto's avatar
TbombToronto
Frequent Visitor
5 years ago
Solved

Creating new rows based on previous rows

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 existin...
  • Jimmy801's avatar
    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