Forum Discussion
Insert row when conditions met on existing data
- 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 CombineCopy 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
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
Thanks Jimmy801 ! I made a few modifications, but your code worked! New rows were added with the information I need.
Thanks for answering another one of my questions!
Cheers.
Dan