Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rafaelsmoreno
Frequent Visitor

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 4
v-yuta-msft
Community Support
Community Support

@rafaelsmoreno

 

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.

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. 

Zubair_Muhammad
Community Champion
Community Champion

@rafaelsmoreno

 

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

 

 

 

 


Regards
Zubair

Please try my custom visuals

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, 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors