0

I am trying to create a calculated column using DAX in powerbi with multiple conditions. I wrote the below query using Switch function but it only accepts two arguments. Is there any way I can change it using If else or other?

Group= SWITCH( TRUE(), AND(Table1[Product] = "Appliances"), "Home", AND(Table1[Table1] = "Utensils"), "Home",

AND(Table1[Product] = "Crane"), "Building",

AND(Table1[Product] = "Agriculture", Table 1[ProductType]="Tractor"), "Agricultural Products",

AND(Table1[Product] = "Car",Table1[ProductType]!="Bicycle"), "Large Transportation", "null" )

1 Answer 1

0

You don't have to use the AND(x1, x2) function. You can use the && and || operators to chain as many as you like. You call also use IN for multiple "or" values, and use NOT... IN... for multiple nor values.

An example:

Group =
  var p = [Product]
  var pType = [ProductType]
  return
    SWITCH( TRUE(),
      p = "Appliances", "Home",
      p = "Agriculture" && pType = "Tractor", "Agricultural Products",
      p = "Car" && NOT pType IN { "Bicycle", "Skateboard", "Unicycle" }, "Large Transportation",
      "null"
   )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.