Switch - Multiple Condition Assignment

  • Last update:January 06, 2025
  • Overview

    1. Function Definition

    The SWITCH function can make judgements on multiple conditions and return corresponding results based on different values.

    iconNote:
    The Else statement is not supported in the SWITCH function.

    Syntax

    SWITCH(Expression,Value1,Result1,Value2,Result2,...,Other results)

    If the result of the expression is Value1, the function returns Result1. If the result of the expression is Value2, the function returns Result2. If there is no matching value, the function returns other results.

    Parameter 1

    Expression

    Parameter 2

    Result

    Result1, Result2..., and Other results, must be the same type of data.

    Other results can be the default value. In this case, if the expression value does not have a corresponding result, the function will return empty.

    2. Notes

    • At least three parameters are required.

    • At least 3 parameters are required for real-time data, and the result parameters must be of the same type.

    • If the parameter is of the date type, the function needs to nest a date function inside, for example, SWITCH(Date,TODATE("2022/01/01"),"1")

    3. Example

    Formula

    Result

    Note

    SWITCH(1+2,3,"today is Wednesday",4,"today is   Thursday")

    Today is Wednesday

    SWITCH(5,3,"Today is Wednesday",4,"Today is   Thursday","Friday")

    Friday

    Example

    When you need to judge many conditions, it may be cumbersome to use the IF function to judge each condition. In this case, the SWITCH function can be used for multiple condition assignment.

    For example, you can set the class name by the SWITCH function. If the current value is Class1, display "Class A"; if it is Class2, display "Class B"; if it is Class3, display "Class C"; otherwise, display "Class D".

    Sample Data:Score Table.xlsx

    Adding Data

    1. Upload Score Table to FineBI. Click My Analysis and click New Analysis. Click Local Excel > Upload Data in the pop-up box, as shown in the following figure.

    image 3.png

    2. After clicking Upload Data, click OK to upload the data and create the analysis subject, as shown in the following figure.

    image 4.png

    Perform Condition Assignment

    1. Open the dataset editing page, click Formula Column, and enter SWITCH(Class,"Class1","Class A","Class2","Class B","Class3","Class C","Class D"). Enter the column name as Class in Alphabetical Order, and click OK, as shown in the following figure.

    iconNote:
    The Class field in the formula is not manually entered, but selected from the fields on the left.

     image 5.png

    2. The following table describes the formula.

    Formula

    Description

    SWITCH(Class,"Class1","Class   A","Class2","Class B","Class3","Class   C","Class D")

    If the data is Class1, it will be assigned as Class A; if it is Class2, it will be assigned as Class B; if it is Class3, it will be assigned as Class C; otherwise, the result will   be displayed as Class D.

    Effect Display

    The following figure shows the effect.

     image 6.png

    附件列表


    主题: Advanced Data Analysis
    Previous
    Next
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    8s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy