Forum Discussion
Conditional Table.ReplaceValue (if to define it replace will be applied or not)
Hi
I have query with 3 columns: InvoiceNumber, InvoiceType and InvoiceAmount. There are 40K+ records, and half a dozen of them have the wrong InvoiceType (need to change com "Service" to "Product"
So, I put up this code:
replaceType =
if "InvNumber" = "30881" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "30769" and "InvType" = "Service" then Table.ReplaceValue(PreviousStep, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "30770" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "30771" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "30772" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "30791" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "31261" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "31262" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "31336" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else if "InvNumber" = "31337" and "InvType" = "Service" then Table.ReplaceValue(replaceCarga, "Service", "Product", Replacer.ReplaceText, {"InvType"})
else "InvType"="InvType"
in
replaceType
The thing is it is not working at all. I don't know how to instruct a "do nothing" in the last else. Any ideas?
4 Replies
- Zubair_MuhammadCommunity Champion
I believe you can also create a quick table of replacements and then merge the 2 fields of both tables
InvNumber InvType Correct Replacement 30881 Service Product 30769 Service Product 30770 Service Product - rafaelsmorenoFrequent Visitor
Zubair, that seems to be the easier way to go, thanks for that. I'll use it, because in the end of the day, it solves the problem.
In the meantime I really wanted to improve my "IF" skills. This "do nothing' at the end of the if then else statement is really troublesome. Let's see if somebody come up with an insight on that.
Best regards,
- v-yuta-msftCommunity Support
Is this query a custom function or others? Which error occurs when you implement it?
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- rafaelsmorenoFrequent Visitor
Hi
It's the standard replace value function from power query. The point is that I cannot make it work with if statements inside it.