Forum Discussion
How to replace a value based on multiple conditions
- Anonymous4 years ago
HI davidoz,
You can try to add a custom column with the below if statement expressions to do replace value operations:
#"Added Custom" = Table.AddColumn(#"Changed Type","Replace", each if [PHASE_NAME] = "Flowback" and [TYPE] = "Separators > 100-285psi Storage Separator" then if [JOB] = "DJ-229" then "ST-0033" else if [JOB] = "DJ-50" then "ST-0014" else if [JOB] = "DJ-85" then "ST-0098" else [NAME] else [NAME] )Full query:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsvJL09KTM5W0lEKTi1ILEosyS8qVogpNTAwTlUwNDDQNbIwLSjOVAgGiiempyrAFQE1uHjpGhlZAhk+wbpA9cZKsToUG2hqADPPxIQa5lmYwswzNKSGeUaGVPawhakhsgtjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PHASE_NAME = _t, TYPE = _t, JOB = _t, NAME = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"PHASE_NAME", type text}, {"TYPE", type text}, {"JOB", type text}, {"NAME", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type","Replace", each if [PHASE_NAME] = "Flowback" and [TYPE] = "Separators > 100-285psi Storage Separator" then if [JOB] = "DJ-229" then "ST-0033" else if [JOB] = "DJ-50" then "ST-0014" else if [JOB] = "DJ-85" then "ST-0098" else [NAME] else [NAME] ) in #"Added Custom"Regards,
Xiaoxin Sheng
davidoz add new custom column in Power Query, let's call it New Name
if [JOB] = "DJ-229" AND [PHASE_NAME] = "Flowback" AND [TYPE] = "Separators > 100-285psi Storage Separator" and [Name] = "LS-0033" then "ST-0033" else [Name]
after the above column is added, remove the existing Name column and rename New Name to Name. Change the logic as you see fit.
✨ Follow us on LinkedIn
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡