Forum Discussion

Bebo's avatar
Bebo
Icon for Helper II rankHelper II
3 years ago
Solved

Replace Value in One Column based upon condition in another Column

I am trying to create a dax expression that will replace the value in one column based upon a condition in another column. For instance, in the following table, if the "gamecode=1" in Type Column), replace "1" in TypeID column with "Game 1".

Any suggestions?

 

Type

Type ID

gamecode

0

gamecode

1

sensor state

1

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Bebo,

    You can create a calculated column with SUBSTITUTE function to repalce values based on other column values:

    Replaced =
    IF (
        Table[Type] = "gamecode",
        SUBSTITUTE ( Table[Type], "code", Table[Type ID] )
    )

    Regards,

    Xiaoxin Sheng

  • Bebo's avatar
    Bebo
    3 years ago

    Thank you - worked perfectly.

4 Replies

  • Bebo with DAX you cannot replace the value but you can add another conditional column

     

    New Type Column = 
    IF ( Table[Type] = "GameCode", "Game 1", "Else Value" )

     

     

    Follow us on LinkedIn and  to our YouTube channel

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort 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.

     

     

     

    • Bebo's avatar
      Bebo
      Icon for Helper II rankHelper II

      Thanks you for the quick response.

       

      I could not get that to work. What I am trying to is this:

      If Column Type = "game code" AND Column TypeID = "1", Output in conditional column would be "Game 1". Then I would repeat this for other TypeID numbers.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Bebo,

        You can create a calculated column with SUBSTITUTE function to repalce values based on other column values:

        Replaced =
        IF (
            Table[Type] = "gamecode",
            SUBSTITUTE ( Table[Type], "code", Table[Type ID] )
        )

        Regards,

        Xiaoxin Sheng