Calculated column configuration
This document describes how to create a calculated column, which is a new data column derived from existing ones in a data table. Calculated columns let you efficiently expand table data and flexibly support various business scenarios.
Example
Consider a student grade table with Chinese, Math, and English scores for each student. You can configure a calculated column to add a new "Total Score" column.
Student name | Chinese score | Math score | English score |
Alex | 88 | 86 | 87 |
Ben | 91 | 93 | 95 |
The logic for the calculated column is: Total Score = Chinese Score + Math Score + English Score. After you configure the calculated column, the new table appears as follows:
Student name | Chinese score | Math score | English score | Total score |
Alex | 88 | 86 | 87 | 261 |
Ben | 91 | 93 | 95 | 279 |
Procedure
Go to the relevant bot space and navigate to Knowledge Base > Table Management > Data Table Management.
Click Edit next to the data table where you want to add a calculated column.
On the table editing page, click Add Calculated Column.

Configure the calculated column as follows:
Configuration using four arithmetic operations
In the Field Expression section, select Chinese Score, Math Score, and English Score from the Field drop-down list. The corresponding field names are automatically added to the expression editor.

Configuration using a function
To add a calculated column for the average math score, follow these steps:
In the Field Expression section, select AVG from the Function drop-down list. The function is automatically added to the expression editor.
From the Field drop-down list, select the Math Score field. The field name is automatically added to the expression editor.

Click OK to add the calculated column.
Appendix
Configuration rules
When you add a calculated column, you must configure the following parameters:
Field Name in English: If the data source is a database, this is the field name from the database. If the data source is a table file, this is the English field name from the table template or a name automatically translated by the system.
Business meaning: Describes the business context of the field. This parameter directly affects information retrieval and question-answering performance, so fill it out carefully.
Field Type/Output Format: The output format for the field in the bot's answers. The following field types are supported:
Numeric range format: The first number must be less than the second number. Values must be numbers or decimals and cannot contain thousand separators. Example: [10000, 20000].
Numeric array format: Values must be numbers or decimals and cannot contain thousand separators. Example: [3000, 10000, 20000].
Date range format: The first date must be earlier than the second date. The date format must be "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss". You cannot mix both formats in the same field. Example: ["2023-11-01 00:00:00", "2023-11-11 00:00:00"].
Date array format: The date format must be "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss". You cannot mix both formats in the same field. Example: ["2023-11-01", "2023-11-11", "2023-10-22"].
Text array format: All elements must be text and enclosed in double quotation marks. Example: ["Excellent performance", "Stable and reliable", "Ready to use", "Elastic scaling"].
Field Description: Explains the field's meaning, usage, and other important notes. This parameter affects question-answering performance, so fill it out carefully.
Field Expression: You can use built-in system functions and basic arithmetic operations to configure the expression for the new field. After configuration, you can verify the data in the Data Preview section.
Supported functions
You can use built-in system functions and basic arithmetic operations to configure expressions for calculated columns.
Built-in system functions
SUM function
Usage: SUM(expr)
Description: Returns the sum of the values in the expression.
Example: SUM(order_amt)
Parameter: The parameter must be a numeric type.
MAX function
Usage: MAX(expr)
Description: Returns the maximum value of the expression across all records. For text types, it returns the maximum ASCII value.
Example: MAX(order_amt)
Parameter: The parameter can be a numeric, text, or date type.
AVG function
Usage: AVG(expr)
Description: Returns the average of the values in the expression as a number.
Example: AVG(order_amt)
Parameter: The parameter must be a numeric type.
COUNT function
Usage: COUNT(expr)
Description: Returns the number of items in the expression.
Example: COUNT(shop_id)
Parameter: The parameter can be any data type.
DATEDIFF function
Usage: DATEDIFF(end_date, start_date)
Description: Returns the number of days between start_date and end_date. If end_date is earlier than start_date, the function returns a negative number.
Example: DATEDIFF(Shipping Date, Order Date) calculates the number of days between the order date and the shipping date.
Parameters:
end_date: A date-type field from the dataset. It must be in the same format as start_date.
start_date: A date-type field from the dataset. It must be in the same format as end_date.
CASE WHEN function
Usage:
CASE WHEN condition1 THEN value1
WHEN condition2 THEN value2
WHEN condition3 THEN value3
ELSE value4
END
Description: Returns a value based on one or more conditions.
The condition must be a complete logical expression, consisting of an expression, a comparison operator, and a comparison value. Examples: a+b>8, City="Beijing", (A > B)=TRUE.
All conditions must consistently use, or consistently not use, aggregate functions.
If both a condition and its corresponding value reference a variable, they must either both use an aggregate function or both not use an aggregate function.
All values returned by the THEN and ELSE clauses must have the same data type (for example, all numbers or all text).
Examples:
Correct example: Grouping users
CASE WHEN COUNTD(order_id)>3 THEN 'Active paying user'
WHEN COUNTD(order_id)>0 AND COUNTD(pay_no)<3 THEN 'General paying user'
WHEN COUNTD(order_id)=0 THEN 'Potential paying user'
END
Incorrect example 1: Inconsistent data types in return values
CASE WHEN COUNTD(pay_no)>3 THEN 1
WHEN COUNTD(pay_no)>0 AND COUNTD(pay_no)<3 THEN '0'
WHEN COUNTD(pay_no)=0 THEN 'Potential user'
END
Incorrect example 2: Mixing aggregate and non-aggregate functions in conditions
CASE WHEN COUNTD(pay_no)>3 THEN 'Active user'
WHEN pay_no>0 AND pay_no<3 THEN 'General user'
WHEN COUNTD(pay_no)=0 THEN 'Potential user'
END
Supported arithmetic operations
Basic arithmetic operations
Addition:
Operator: +
Example: a+b
Subtraction:
Operator: -
Example: a-b
Multiplication:
Operator: *
Example: a*b
Division:
Operator: /
Example: a/b