Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello guys,
I'm trying to replace multiple values of a column based on a multiple OR condition in a single step of Power Query.
This column should only have 4 correct values, for example: value1, value2, value3, value4 the others values I must replace with wrong value.
This is my formula, however it doesn't work correctly.
= Table.ReplaceValue(#"Changed type",
each [Column],
each if ([Column] <> "Value1" or [Column] <> "Value2" or [Column] <> "Value3" or [Column] <> "Value4") then "wrong value" else [Column],
Replacer.ReplaceText,{"Column"})
I also tried with this formula without success
= Table.ReplaceValue(#"Changed type",
each [Column],
each if ([Column] <> "Value1" then "wrong value"
else if [Column] <> "Value2" then "wrong value"
else if [Column] <> "Value3" then "wrong value"
else if [Column] <> "Value4" then "wrong value")
else [Column],
Replacer.ReplaceText,{"Column"})
I know there are other alternative solutions like a conditional column or with DAX, but I have to do it in PowerQuery without creating a new column.
Thanks for your help!
Solved! Go to Solution.
No matter what text [Column] contain, your logic returns "wrong value" since C <> A or C <> B is always true unless A=B.
Suppose [Column] = "Value4". Then since "Value4" <> "Value1", your logic returns "wrong value".
Suppose [Column] = "Value1". Then since "Value1" <> "Value2", your logic returns "wrong value".
Try this instead:
= Table.ReplaceValue(
#"Changed Type",
each [Column],
each if not List.Contains({"Value1", "Value2", "Value3", "Value4", "Value5"}, [Column])
then "wrong value"
else [Column],
Replacer.ReplaceText,
{"Column"}
)
No matter what text [Column] contain, your logic returns "wrong value" since C <> A or C <> B is always true unless A=B.
Suppose [Column] = "Value4". Then since "Value4" <> "Value1", your logic returns "wrong value".
Suppose [Column] = "Value1". Then since "Value1" <> "Value2", your logic returns "wrong value".
Try this instead:
= Table.ReplaceValue(
#"Changed Type",
each [Column],
each if not List.Contains({"Value1", "Value2", "Value3", "Value4", "Value5"}, [Column])
then "wrong value"
else [Column],
Replacer.ReplaceText,
{"Column"}
)
= Table.ReplaceValue(#"Changed type","","",(x,y,z)=>if List.Contains({"Value1","Value2","Value3","Value4"},x) then x else "wrong value",{"Column"})
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 5 | |
| 5 |