Forum Discussion

1001's avatar
1001
Resolver II
3 years ago
Solved

Write a SWITCH statement for a range of Numbers

Hi, I have to write a DAX for a calculated column to group a range of numbers from another column. Just wondering how to do this?

1-8 = "short"

9-15="Medium"

16-30="Long".

 

Many thanks.

  • hi 1001 

    this shall also work:

    Column2 =
    SWITCH(
        TRUE(),
        [Column1]<=8,  "Short",
        [Column1]<=15, "Medium",
        [Column1]<=30, "Long",
        "Others"
    )

3 Replies

  • hi 1001 

    try like:

    Column2 =
    SWITCH(
        TRUE(),
        [Column1]>=1&&[Column1]<=8,  "Short",
        [Column1]>=9&&[Column1]<=15, "Medium",
        [Column1]>=16&&[Column1]<=30, "Long",
        "Others"
    )
    • FreemanZ's avatar
      FreemanZ
      Super User

      hi 1001 

      this shall also work:

      Column2 =
      SWITCH(
          TRUE(),
          [Column1]<=8,  "Short",
          [Column1]<=15, "Medium",
          [Column1]<=30, "Long",
          "Others"
      )
      • 1001's avatar
        1001
        Resolver II

        Thanks Freeman, appreciate that.