Dataset FAQ

Updated at:

This topic answers frequently asked questions about creating datasets.

Custom SQL errors

If you encounter an error when running or saving your custom SQL, first check for these common causes.

1. Incorrect custom SQL syntax

Quick BI processes a custom SQL query before sending it to the database for execution. This process includes parsing placeholders, adding a LIMIT clause to restrict the number of rows, and adding SQL comments. If your custom SQL has syntax errors, the database returns an error.

If your custom SQL query fails, run the statement directly in your database to check for syntax errors. You can find previously executed SQL statements in History.

image

2. Statements placed before the SELECT clause

To prevent performance issues from querying large amounts of data, Quick BI adds a LIMIT clause to the outermost layer of your custom SQL query before sending it. This requires the custom SQL to begin with a SELECT statement. You cannot write a HINT statement directly in the panel. If you place other statements before the SELECT clause, the custom SQL query will fail.

If you need to set a HINT statement, use the Set HINT Statement option at the top of the editor.

For a list of data sources that support HINT statements, see Data source advanced feature support list.

image

3. Missing default values for placeholders

In Quick BI, you can use placeholders in a custom SQL query to pass parameters. When viewing a report, you can use a query control to pass values to the placeholders in the underlying SQL, allowing for flexible data analysis. For more information about how to use placeholders, see Placeholders.

If a placeholder is used in a SELECT statement, you must assign it a default value. Otherwise, the SQL query will be incomplete and cause an error.

For example, in the following code, the value placeholder $val{profit_range} does not have a default value. This prevents the "Order Level" field from being calculated, which causes the custom SQL to fail. After you assign a value of 100 to the placeholder and rerun the SQL, the data is displayed correctly.

To prevent report errors from unassigned values, we recommend setting a Global default value for placeholders in SELECT statements, not just a Dataset Only value.

SELECT report_date, order_level, shipping_type,price,order_number,area,
   case when profit_amt< $val{profit_range} then'Loss' 
   when profit_amt> $val{profit_range} then'Profit'
   else 'Break-even'
   end 'Order Level'
from company_sales_record
where $expr{report_date :report_date}
and $expr{order_level :order_level}
and $expr{order_number :order_number}

image

image

4. Other issues

Use standard conventions for comments and aliases in your custom SQL. Non-standard syntax can cause failures due to special characters in field names or placeholder parsing errors.

Do not add a semicolon (;) at the end of your custom SQL.

Common calculated field errors

  1. Calculated fields reference physical fields. If you need to convert a field's data type, you must use the corresponding conversion function. Manually changing the data type in the UI does not change the type of the underlying physical field and may lead to data type mismatch errors.

  2. You cannot use aggregate functions, such as SUM or AVG, in a dimension-based calculated field. To perform aggregation, save the field as a measure.

  3. Text fields only support COUNT and COUNTD aggregations. They do not support aggregate functions like SUM or MAX. You must convert the field to a numeric type before performing these calculations.

Creating datasets from local files

When you create a dataset from an uploaded local file, you must follow the SQL syntax of the database where the file is stored. For example, if you upload a file to an exploration space, you must use ClickHouse syntax when creating the dataset.

When you upload a file to an exploration space, you cannot use custom SQL or create cross-source associations to create a dataset. To create a dataset with cross-source associations, upload the file to a data source within a group space that supports this feature. If you use custom SQL to create a dataset from a file uploaded to a database data source, your query must reference the physical table name that is automatically generated in the database, not the name of the uploaded file. To find the physical table name, navigate to the file list in your data source, click the Settings icon for the file, and view the physical table name on the Modify File Upload page.image

image

Converting Unix timestamps

When a time field is stored as a Unix timestamp and its data type is text or numeric, you must use the from_unixtime function to convert it.

  1. On the dataset edit page, create a new calculated field as shown in the following figure.image

  2. Save and refresh the dataset. The result appears as shown in the following figure.image

Displaying null or empty values

1. Configure the display style for empty values in the dataset.

image

2. Configure the display style for empty values in the dashboard.

image

Using parameterized SQL for ratio calculations

Quick BI does not directly support ratio calculations. However, you can create a dataset using parameterized SQL to calculate ratios.

Assume your data table has the following structure: date, province, city, and order_amt (sales amount). You need to aggregate by city, calculate the ratio of each city's sales to its province's total sales, and allow users to select any date range and multiple provinces and cities.

This example uses parameterized SQL to build the dataset model. See the following sample SQL:

select a.city,sum(fenzi)/sum(fenmu) as ratio
from
(select province,city,sum(order_amt) fenzi
 from  zhanbi_test
 where  $expr{date:date_para}
 and    $expr{province:province_para}
 and    $expr{city:city_para}
 group by province,city
)a
left  join
(select province,sum(order_amt) fenmu
 from  zhanbi_test
 where  $expr{date:date_para}
 and    $expr{province:province_para}
 and    $expr{city:city_para}
 group by province
)b on a.province=b.province

The preceding SQL aggregates data by the city field, but you can adapt it for other fields. After creating the parameterized SQL, you must convert the date parameter to a date data type in the dataset parameter settings. You can then create the dataset and display it in a dashboard.

Using parameterized SQL for cumulative calculations

By default, Quick BI supports several built-in date accumulations, including year-to-date, all-time total, month-to-date, quarter-to-date, and custom. If your dataset uses a fiscal year and the date field is a fiscal year field, you can also use fiscal-year-to-date and fiscal-quarter-to-date accumulations for daily data. For more information, see Date accumulation.

To configure these calculations, you must select a date-type day field in the dimension list, as shown in the following figure.image

To calculate cumulative values for a custom time range that starts from a selected date, use parameterized SQL. The following SQL statement is an example of a month-to-date calculation:

select  a.mon_date,avg(a.order_num) order_num,sum(b.order_num) add_num
from (
select date_format(report_date,'%Y/%m') mon_date,count(distinct order_id) order_num,max(date_format(report_date,'%Y/%m')) max_mon_date
from  company_sales_record_copy
where  $expr{report_date:month_date}
group by date_format(report_date,'%Y/%m')
)a
left join(
select date_format(report_date,'%Y/%m') mon_date,count(distinct order_id) order_num
from  company_sales_record_copy
where  $expr{report_date:month_date}
group by date_format(report_date,'%Y/%m')
)b on a.max_mon_date>=b.mon_date
group by a.mon_date        

In your dashboard, link the query control to the parameter field. This allows users to filter by different month ranges and view the cumulative value for each month, starting from the beginning of the selected range.

Querying the last N days with a single date

By default, if you input a single date, Quick BI displays data for only that date. To display data for a date range, you must input a date range. To filter two charts—for example, showing one with data for a specific day and another with data for the next three days—use parameterized SQL. See the following sample SQL:

select   report_date,area,product_type,count(distinct order_id) order_num
from   company_sales_record
where  area in ('Southwest','Northwest','North China')
and    ( $expr{dateadd(report_date,1,'dd'):date1}
or      $expr{dateadd(report_date,2,'dd'):date1}
or      $expr{dateadd(report_date,3,'dd'):date1})
group by area,product_type,report_date

Row-level security

Yes. For more information, see Row-level security.

Default row display limit

A dataset displays 100 rows by default.

Dataset pagination

No, pagination is not supported for dataset data previews.

New field display issues

If the new field is an aggregated calculated field, it does not appear in the data preview.

image

Using geographic data in map charts

On the dataset edit page, convert the geographic data fields to the appropriate geographic information type by changing their dimension type.

image

For more information, see Create a dataset.

Using descriptions as field names

In your workspace settings, you can choose to use table names or remarks as field names when creating datasets.

Alternatively, in the batch configuration panel for dataset fields, you can select multiple fields and apply their descriptions as field names in bulk.

image

Note
  • If a field's description is empty, you cannot use it as the field name.

  • If you create a dataset with custom SQL, you must set an alias for each field within the SQL statement to define its name.

Updating datasets after physical table changes

If a physical field cannot be found, Quick BI does not automatically delete it because it might be used in analyses or dashboards. On the dataset canvas, click the table. The panel on the right displays any field changes, allowing you to delete invalid fields with a single click.

Creating datasets from multiple databases

Drag the data tables from the two databases onto the canvas, configure the join relationship, and then extract the data using the Quick engine. For a list of data sources that support acceleration with the Quick engine, see Data source advanced feature support list.

Copying datasets between workspaces

You can use the cross-workspace dataset copy feature. For more information, see Copy a dataset across workspaces.

Configuring association models

For more information, see Build a model.

Configuring an association model is similar to using a JOIN clause in a SQL statement. You can configure association models on the dataset edit page. For more information, see Build a model.image

Benefits of dataset caching

Dataset caching accelerates report access and reduces the load on your database. For example, after caching is enabled for a dataset and a report is accessed for the first time, subsequent requests for the same report are served directly from the cache, eliminating the need to query the database again.

Optimizing slow SQL queries

1. Optimize the SQL logic to use indexes, or create a database view to avoid complex joins and speed up queries.

2. Configure global default values for SQL placeholders to prevent full table scans on large datasets.