Forum Discussion

davidoz's avatar
davidoz
Frequent Visitor
4 years ago
Solved

How to replace a value based on multiple conditions

I have a data feed coming from an external system into PowerBI. Over a number of months, several users selected incorrect data in that system and now I need to clean it up in PowerBI because unfortun...
  • Anonymous's avatar
    Anonymous
    4 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