ajDBCountRecord function
Description
The ajDBCountRecord function counts the number of records in a database table satisfying the criteria specified in filter_condition. Please take note that to run this function from Excel, you would need to set up the Data Source Connection in ##ExternalResources.
Syntax
ajDBCountRecord( table_name, [filter_type], [filter_condition], [table_schema], [data_source_id], [run_condition], [run_by_function_point_only] )
Argument Name | Argument Type | Description |
---|---|---|
table_name (required) | String | The name of the table to read from. |
filter_type (optional) | Double | The type of filtering. 3 types are supported 0, 1 and 2. |
filter_condition (optional) | Range / Array | The range that defines the filter condition. filter_type = 0. The range defines the WHERE clause of a SQL statement. The range will be concatenated into a single string. For example, Name = 'peter' and class = 'B'. filter_type = 1. The range defines the filter condition in the Kendo grid style. Click Insert Snippet\Filter Condition (Filter Type 1) to add the preset required format. filter_type =2. The range defines a filter condition similar to the format used in MS Query. Click Insert Snippet\Filter Condition (Filter Type 2) to add the preset required format. Refer to the Filter Condition snippet to see how you can use this snippet to define the required fields for filter type 1, 2. |
table_schema (optional) | Range / Array | The range that defines the DB Schema. |
data_source_id (optional) | String | The data source shall be used in this database operation. It shall be defined in ##ExternalResources worksheet. The default value is "primary". |
run_condition (optional) | Boolean | The extended function will run when the value is TRUE. Otherwise, it will not run. The default value is TRUE. |
run_by_function_point_only (optional) | Boolean | If it equals FALSE, the function can be executed through ‘Excel Calculation’ (can be either Automatic or Manual, Calculate Now or Calculate Sheet) or Preview Function Point. If it equals TRUE, the function can be executed with Preview Function Point (AlchemyJ ribbon \ Preview Function Point) only. The default value is TRUE. |
The function will return:
1) Return Value: Number of records.
2) Return Type: Single Value / Multiple values (array formula)
Example
We will use the following table in our examples. The table name is tb_customer. It has 5 columns and 5 rows.
Example 1
Count all records from the table.
Example 2
Count the records where Gender is F using filter_type 0.
Example 3
Count the records where Customer Level is 1 or 2 using filter_type 1. The filter condition table was created via AlchemyJ ribbon Insert Snippet and select Filter Condition (Filter Type 1) .
Example 4
Count the records where Gender equals 1 and Customer Level is greater than 2 using filter_type 2. The filter condition table was created via AlchemyJ ribbon Insert Snippet and select Filter Condition (Filter Type 2) . In addition, the table column names are mapped to the data name in DB Schema. Therefore, it uses the data name in the filter_condition.
Click here to download the use case workbooks for further reference.
Error Scenarios
It will return #VALUE! when missing any required parameter or mismatch parameter type. Besides, system will raise error for below scenario(s).
Error Scenario |
---|
DB connection error. |
Table name is empty. |
Filter type is invalid, it must be 0, 1, or 2. |
Data name in filter condition does not exist in the provided table schema. |
Total number of filter condition columns is not even number. |
Data name in filter condition is empty. |
Operator in filter condition is empty. |
Invalid operator value in filter condition. |
And/Or in filter condition is invalid. |
Content in filter condition range does not meet the expected format of specified filter type. |
Table name does not exist in provided DB Schema. |
The table schema columns are invalid. |
The table schema range does not include a header or a row of data. |
The provided column header cannot be found in the specified table schema range. |
Column header is not a single row range or a single column range. |