Create a Metric using Custom SQL

This guide provides a step-by-step approach to utilizing custom SQL for creating metrics, which can enhance your data analysis capabilities.

  1. Access Custom SQL

On the Create Metric page, select the "Custom Query" option.

  1. Query Execution

  • Enter your custom SQL in the </> Query Editor.

  • Click "Format Query with AI" to convert your query into DataBrainโ€™s recommended format.

  • After reviewing, click "Run Query" to execute it.

  1. Preview the Results

  • Check the Query Result section to see your raw SQL output in a table.

  • You can download this data as a CSV file if needed.

  1. Save your Query Result

Once youโ€™re satisfied with the output, click on "Use Results >" option. You can save the result in different ways:

  • Table Chart

  • Table Chart with Dynamic Table property - It automatically adjusts to match the latest structure of your SQL query results. It works best when your query uses SELECT * โ€” so any new or changing columns are always included in the table without needing manual updates. This makes it ideal for exploring flexible or evolving datasets.

  • New Chart

  • Custom Dataset

Use as Table Chart

  • To save as a Table Chart, click "Use as Table Chart".

  • Configure any additional settings and save it to your dashboard.

Publish as Custom Dataset

  • Provide a name and choose the schema for your custom dataset.

  • Click "Save" to publish it.

New Chart

  • Select the chart type that best represents your data.

  • Configure it and save it to your dashboard.

  1. Edit Custom query

  • You can switch between the Chart Builder and the Query Editor at any time.

  • Modify your query and see the updated results instantly in both the Query Result and Chart Builder.

Last updated