Forum Discussion

daniegajohnson's avatar
daniegajohnson
Frequent Visitor
6 years ago
Solved

Insert row when conditions met on existing data

Hey All, I am looking to add new rows to my data using values from the existing rows. Their are around 600,000 rows of data at the moment. Here is a parsed down sample: Lookup ID Transaction Da...
  • Jimmy801's avatar
    Jimmy801
    6 years ago

    Hello daniegajohnson 

     

    try out this solution. if filters the table and applys the changes requested by you. After that both tables are combined.

    let
    	Source = #table
    	(
    		{"Lookup ID","Transaction Date","Type","Quantity","Net Amount","Membership Level","Membership Transaction Type","Membership Promotion Name","Membership Promotion Type","Membership Promotion Amount"},
    		{
    			{"123456789","43814","Membership"," 1"," 95"," Family"," Join","Groupon Membership Discount","Discount"," 95"},	{"123456780","43828","Membership"," 1"," 95"," Family"," Renew"," Expired Groupon Discount","Discount"," 75"}
    
    					}
    	),
        ChangeType = Table.TransformColumnTypes(Source,{{"Membership Promotion Amount", Int64.Type}, {"Net Amount", Int64.Type}}),
        FilterForDiscount = Table.SelectRows
        (
            ChangeType,
            each [Type] = "Membership" and [Membership Promotion Type] = "Discount"
        ),
        DeleteNetAmountType = Table.RemoveColumns(FilterForDiscount,{"Net Amount", "Membership Transaction Type"}),
        AddedNewAmount = Table.AddColumn(DeleteNetAmountType, "Net Amount", each [Membership Promotion Amount]*-1),
        AddedNewType = Table.AddColumn(AddedNewAmount, "Membership Transaction Type", each [Membership Promotion Type]),
        Combine = Table.Combine({ChangeType, AddedNewType})
    in
    	Combine

     

    Copy paste this code to the advanced editor to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query, or I could create a custom function what makes it easier to apply if you are not used that much to power query.

    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