Switch

  • Last update:  2022-04-15
  • 1. Overview

    1.1 Problem description

    When there are many conditions that need to be judged, it will be more troublesome to use IF function to judge each case, so you need to nest layers and write multiple expressions.

    For example, there are two fields in the summary table, a city code, a sales, you need to convert the city code to a city name.

    30.png

    1.2 Implementation idea

    In this case, you can use the switch function to determine multiple cases by writing just one expression.

    SWITCH(expression, value1, result1, value2, result2, ... )

    If the result of the expression is value 1, the whole function returns result 1.

    if the result of the expression is value 2, the whole function returns result 2.

    if the result of the expression is value 3, the entire function returns result 3.

    Note: Adding else judgments to the Switch function is not supported.

    1.3 Function description

    Judgment of multiple cases, used in cases where there are many judgment conditions.

    1)Overview

    GrammarSWITCH(expression,value1,result1,value2,result2,……)If the result of the expression is the value 1, the whole function returns the result 1 If the result of the expression is the value 2, the whole function returns the result 2, if the result of the expression is the value 3, the whole function returns the result 3, etc.
    parameter1expression-
    parameter2resultAll of result 1, result 2, result 3 ...... must be the same type of data.

    2)Cautions

    At least three parameters.

    Note: The number of parameters in the real-time data is at least 3, and the resultant parameters are of the same type.

    3)Example

    FormulaResultRemarks
    SWITCH(1+2,3,"Today Wednesday",4,"Today Thursday")Today Wednesday

    2. Example

    Example data: switch function use.xlsx

    2.1 Create a Self-service dataset

    Go to Data Preparation and add the sample data to BI.

    Create the Self-Service dataset as shown in the following figure.

    20.png

    2.2 Add new column

    In the new Self-Service dataset, select "New Column", edit the formula: SWITCH(City, "Wan A", "Hefei", "Wan B", "Wuhu", "Wan C", "Bengbu", "Wan D", "Wan South", "Wan E", "Maanshan") and select the new column type as "Text", enter the new column name and click "OK", the following figure shows.2.png

    Note: The city in the formula is not entered manually, but selected by clicking in the field on the left.  

    2.3 Data preview

    The effect of the data can be seen in the preview data box as shown in the following figure.3.png

    Click the "Save" button in the upper right corner and update the data to use the city name field in the front-end analysis.

    附件列表


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

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

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

    不再提示

    10s後關閉

    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