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
marsclone
Helper IV
Helper IV

Replace table value

I would like to replace the following

If column Artikelcode = 99980 or 99981 and column Artikelgroep = 170101 or 170103 then change column Artikelgroep to 170199

 

I have this formula, but strangely the first "or 170103" is not included in the change. What goes wrong?

 

= Table.ReplaceValue(#"Rijen gefilterd2", each [Artikelgroep], each if [Artikelgroep] = 170101 or 170103 and [Artikelcode] = "99980" or "99981" then 170199 else [Artikelgroep], Replacer.ReplaceValue,{"Artikelgroep"})

 

Thank you in advance

1 ACCEPTED SOLUTION
watkinnc
Super User
Super User

Actually this not strictly an issue with parentheses; even with the parentheses in the prior answer, the expression would cause an error.  You must use an identifier for each and/or clause. This would be correct:

 

= Table.ReplaceValue(#"Rijen gefilterd2", each [Artikelgroep], each if ([Artikelgroep] = 170101 or [Artikelcode]= 170103) and ([Artikelcode] = 99980 or [Artikelcode] = 99981) then 170199 else [Artikelgroep], Replacer.ReplaceValue,{"Artikelgroep"})

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

= Table.ReplaceValue(#"Rijen gefilterd2", each [Artikelgroep], each if List.Contains({170101,170103},[Artikelgroep]) and List.Contains({"99980","99981"},[Artikelcode]) then 170199 else [Artikelgroep], Replacer.ReplaceValue,{"Artikelgroep"})

watkinnc
Super User
Super User

Actually this not strictly an issue with parentheses; even with the parentheses in the prior answer, the expression would cause an error.  You must use an identifier for each and/or clause. This would be correct:

 

= Table.ReplaceValue(#"Rijen gefilterd2", each [Artikelgroep], each if ([Artikelgroep] = 170101 or [Artikelcode]= 170103) and ([Artikelcode] = 99980 or [Artikelcode] = 99981) then 170199 else [Artikelgroep], Replacer.ReplaceValue,{"Artikelgroep"})

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

The issue with your formula is the way you have written the conditions. In the condition [Artikelgroep] = 170101 or 170103 and [Artikelcode] = "99980" or "99981", the or operator has a higher precedence than the and operator.

 

Therefore, the condition is evaluated as follows:

 ([Artikelgroep] = 170101) or (170103 and [Artikelcode] = "99980") or ("99981") 

 

This is not what you intended. To fix this, you need to use parentheses to specify the order in which the conditions should be evaluated.

 

Here is the corrected formula:

= Table.ReplaceValue(#"Rijen gefilterd2", each [Artikelgroep], each if ([Artikelgroep] = 170101 or 170103) and ([Artikelcode] = "99980" or "99981") then 170199 else [Artikelgroep], Replacer.ReplaceValue,{"Artikelgroep"}) 

 

 

This will correctly evaluate the conditions as follows:

 

 

(([Artikelgroep] = 170101) or (170103)) and (([Artikelcode] = "99980") or ("99981")) 

 

 

 

 

 

 

 

 

Thank you very much! 

You let me see how to approach the problem!

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
Top Kudoed Authors