Forum Discussion
Insert row in M query based on condition
Hello experts, need some help. I already spent some time on it and still am not able to figure out. In power query, i need to insert rows, something like
if not text.contains ([field1],"value1" and not Text.Contains([field2], "Value2" THEN Insert rows like below
Table.InsertRows(Table.Final Table( [field1] = "value1", [field2] = "value2",
If Field 1 contains value1 from data source, then don't insert.
How do i acheive this?
thanks a lot,
2 Replies
- johnt75Super User
I think you could use Table.Combine , so your if statement would return the result of combining the previous step with Table.FromRecords or the table constructor, or if you didn't want to insert the row just return the previous step.
- newbie7Frequent Visitor
thanks, i found a workaround, not a good one, but will work probably.
I just inserted rows [field1] = "value1", [field2] = 0 and then gruped by to keep max row value for field 2 for each value in field1. That way when data source has [field1] = "value1", [field2] = 1, it would pick up data source one, and when not, then will keep [field1] = "value1", [field2] = 0 row.
If anybody has better one, please post.