SQL functions on your own data

SQL functions transform, combine or aggregate rows. Run these examples on sample rows or your CSV with xmetric’s DuckDB engine.

Updated

Synthetic worked example · 4 input rows
SELECT coalesce(Amount, 0) AS result FROM input ORDER BY Period

What does this formula return?

Loading the browser engine to calculate this sample…

Edit the sample rowsClick any value · changes recalculate

Empty numeric cells are null. Every input row is used in the calculation.

Use your own CSV
Run it on my CSV

Drop one CSV anywhere. It is calculated in this browser; nothing is uploaded.

Nothing is uploaded.

Original worked examples, sources and questions

The recorded examples below retain their original source rows. The live result above uses the current rows and formula.

SQL functions on your own data

SQL functions transform, combine or aggregate rows. Run these examples on sample rows or your CSV with xmetric’s DuckDB engine.

  • sql coalesce — Replace a null with the first available value. A zero is already a value, so COALESCE leaves it unchanged.
  • sql window functions — Calculate across related rows without collapsing them into a grouped total. ORDER BY and the window frame define this running total.
  • sql like — Match a text pattern: % matches any sequence, and _ matches one character. This LIKE comparison is case sensitive.
  • sql substring — Extract part of a string. The first character is at position 1 in this DuckDB example.
  • sql concat — Join text and values into one string. DuckDB concat skips null inputs; check your target database before relying on null behavior.
  • sql union — Combine query results and remove duplicate rows. UNION ALL keeps the duplicates.
  • sql count distinct — Count distinct non-null values. Repeated values count once.
  • sql cte — Name an intermediate query with WITH, then refer to it in the final SELECT.
  • sql group by — Collapse rows into groups and calculate one total per region. SUM ignores null amounts.
  • sql case when — Choose the first matching branch. A null amount does not satisfy this comparison and uses ELSE.
  • sql between — Test an inclusive range. Both endpoints are included; a null amount returns null.
  • sql cast — Convert a value to another SQL type. A conversion can fail when the value does not fit the target type.
  • sql dateadd — Add an interval to a date. SQL Server uses DATEADD(part, number, date); this browser runs DuckDB date_add(date, interval).
  • sql isnull — SQL Server ISNULL(value, replacement) replaces nulls. DuckDB uses COALESCE for that job; IS NULL tests for null instead. Run the supported COALESCE form below.
  • sql pivot — Turn region values into columns and aggregate the amounts. Select the two needed source columns to avoid unintended grouping.
  • sql round — Round a number to the requested decimal places. This example rounds each amount divided by three to one decimal place.
  • sql left join — Keep every row from the left input and attach its region total from the right query. An unmatched right row would produce null columns.
  • sql datediff — Count date-part boundaries between dates. DuckDB spells this function date_diff; the example counts day boundaries.
  • sql lag — Read the preceding row in the window order. The first row has no predecessor, so its result is null.
  • sql rank — Rank amounts from largest to smallest. Ties share a rank and leave a gap; NULLS LAST puts the null amount at the end.
  • sql replace — Replace matching literal text. This example changes North to N and leaves South unchanged.
  • sql exists — Test whether a subquery returns at least one row. EXISTS returns one boolean here.
  • sql having — Filter after aggregation. WHERE filters source rows; HAVING filters these grouped totals.
  • sql in — Test whether a value belongs to a list. North is included in this list; South is not.
  • sql nullif — Return null when two expressions are equal; otherwise return the first expression.
  • sql trim — Remove leading and trailing spaces. The example adds spaces first so the effect is visible in the formula.
  • sql median — Return the middle of the non-null amounts. The sample values 5, 10 and 20 have a median of 10.

What does the sql coalesce worked example calculate?

Replace a null with the first available value. A zero is already a value, so COALESCE leaves it unchanged.

Updated

What formula and inputs define this worked example?

This worked example uses 4 explicitly supplied input rows and their stated field types. Published inputs, field types and recorded results (JSON) identify the exact example.

The formula for this published example is:

SELECT coalesce(Amount, 0) AS result FROM input ORDER BY Period

DuckDB SQL function documentation provides the language reference. The linked JSON supplies the concrete input and output for this page.

What recorded result comes from this exact sample formula?

For the formula SELECT coalesce(Amount, 0) AS result FROM input ORDER BY Period, the published 4-row input has 4 recorded result rows. These are xmetric sample-example results; they do not establish native Tableau or Power BI parity, workbook coverage or corpus-wide compatibility.

result
10
20
0
5

How can I run this example on my own CSV?

Choose or drop one CSV into the live panel, match fields when the Tableau view requires mappings, and use the raw column names or mapped calculation names in that Tableau formula. Mapped names take precedence if names differ only in capitalization or collide. SQL and DAX use your actual column names. Choose Row calculation to write a new Tableau formula on the raw columns. Opening a CSV alone does not calculate a result; select Run formulas to evaluate the current rows. The panel is a progressive enhancement of the formula and recorded example already present in this HTML.

How do Tableau, DuckDB SQL and scalar DAX differ in this example?

Tableau formulas use the shown field types and view settings. DuckDB SQL reads a table named input; xmetric’s Power BI scalar DAX evaluator reads one table named Sales. Each formula runs independently, so successful execution alone does not establish equivalence.

LanguageFormula supplied on this pageExecution and limitation
TableauIFNULL([Amount], 0)xmetric’s Tableau calculation and view services use the supplied rows. LOD view grain and table-calculation addressing or partitioning affect results; a CSV does not import hidden workbook calculations.
DuckDB SQLSELECT coalesce(Amount, 0) AS result FROM input ORDER BY PeriodDuckDB compiled to WebAssembly executes the entered query over input. Snowflake, BigQuery and other dialects are not executed by this editor.
xmetric Power BI scalar DAXNo scalar DAX measure is supplied for this page.xmetric evaluates one scalar measure over Sales. A CSV does not supply relationships, hidden measures or a multi-table Power BI model.

What else do people ask?

Can xmetric chart this CSV?

This page’s panel returns formula-result rows. Open the xmetric browser app to create a chart from your CSV. The calculation shown here is SELECT coalesce(Amount, 0) AS result FROM input ORDER BY Period; choose dimensions and measures for the question you want to answer.

Does this browser run SQL Server, Snowflake or BigQuery syntax?

This editor runs DuckDB SQL over the table input. SQL dialects differ, so syntax written for SQL Server, Snowflake or BigQuery may need changes. The published query and linked result rows specify the syntax checked on this page.