powerbipowerquerym

Multiple IF Statements in Power Query (PowerBI) "If / Then / Otherwise"


I have a column called "CSI" listing different names formatted as "Last Name - First Name":

All three names above are part of Team 1 and all the remaining names are automatically considered being part of Team 2.

How do I add a new column indicating that the person is part of Team 1 or Team 2?

I tried the formulas below but failed: = if [CSI] = "Doe - John" then "Team 1" else if [CSI] = "Sanders - Colonel" then "Team 1" else if [CSI] = "Jackson - Michael" else "Team2"

= if [CSI] = #text(Doe - John) then "Team 1" else if [CSI] = #text(Sanders - Colonel) then "Team 1" else if [CSI] = #text(Jackson - Michael) else "Team2"


Solution

  • Multiple IFs are rarely a good idea, you could try the following:

    = if List.Contains({"Doe - John", "Sanders - Colonel", "Jackson - Michael"}, [CSI]) 
      then "Team 1" 
      else "Team 2"