Measure tests and preview

A measure test checks that a measure keeps returning the result you expect. The tests live in the Tests pane of the measure editor, and the Preview pane runs the measure itself so you can see its rows. The editor's lower panes are Description, Tests (<n>) and Preview; opening a pane expands the editor if it is collapsed.

What a test checks

A test has a kind, and each kind asks a different question of the measure:

KindWhat it checks
Expected valueThe result matches a value you enter. The value can be a Number, Text, True / false or Null; a null value means the test expects a NULL result.
InvariantA rule always holds: Never negative, Never null, Between min and max, Rows sum to one, or Total equals the sum of its rows.
Oracle SQLThe result matches your own source-of-truth query, written over the model's BI table names. Pick the Value column to compare and, for grouped results, Key columns to match rows; they default to the group-by names.
Shape (runs without errors)The measure runs without errors, over the grain you pick: Card (no group-by), Grouped rows, or Grouped rows and totals.

Tests use one of three grains: Card (no group-by) checks a single value, Grouped rows checks one row per group, and Grouped rows and totals also checks the grand total; a Shape test must have one of them, and the grouped grains need group-by columns.

Expected value, Invariant and Oracle SQL tests can carry a Tolerance (absolute) and a Tolerance (relative). A comparison passes when the gap between the two values is within the larger of the two allowances: the absolute tolerance, or the relative tolerance applied to the expected value.

A test is created by a person or by the AI; an AI-authored test carries an AI chip on its row. For the editor around the panes, see Measure editor; for the measure library and its folders, see Measures.

Add a test

  1. Open the measure and choose the Tests pane. The tab counts the measure's tests, for example Tests (3).
  2. Choose Add test and fill the form: Name, Kind, any Group by columns (up to 10), and a Row limit (the placeholder reads 500).
  3. Fill the fields for the kind you picked. A grouped Expected value test picks the row it checks with Row where <column> is; leave it on Any (the only row) when the query returns a single row.
  4. Save with Add test (or Save test when you edit an existing test). Cancel closes the form, and Edit <name> reopens it.

Run tests

  1. To run one test, choose Run <name> on its row; it runs straight away.
  2. To run a measure's tests together with the tests of the measures that depend on it, choose Run with dependents.
  3. To run every test in the model, right-click Measures in BI tables and choose Run all tests. The run is queued and works in the background; the app follows it and refreshes the tests when it finishes.
  4. To run against SQL you have not saved yet, turn on Against the unsaved SQL; the run uses the expression in the editor.

While a run is going:

The Tests pane notes Without row-level security: tests run without row-level security, so a test can check rows a viewer would not see in a report. See Row-level security and View as.

The Health tab runs all of a model's tests too; see Check, document and trace a model.

Read the results

Each test shows its last stored result:

These results also feed the status dot on the measure's row in BI tables; see Measures.

Limits inside a test

Quotas and time budgets

When a test is refused

Preview a measure

The Preview pane runs the measure itself and shows its rows.

  1. Open the measure and choose the Preview pane.
  2. Optionally set Group by (up to 3 columns) to group the rows; a grouped preview shows up to 100 rows.
  3. Choose Run preview. The control is off while the expression is empty and while a preview runs.

Questions, answered

Can I run one test without running the whole model?

Yes. Choose Run <name> on the test's row; it runs on its own, straight away. Use Run with dependents when the measures that use it should be checked too.

What is the difference between a fail and an error?

A fail means the check did not hold: a value differs, a row is missing, a key is duplicated, or a rule is violated (a Shape test fails when the measure does not run cleanly). An error means the test could not run or compare at all, for example when the query returned more rows than the test's row limit.

Can I run a measure's tests against SQL I have not saved yet?

Yes. Turn on Against the unsaved SQL in the Tests pane and run; the tests use the expression in the editor. Such a run is not stored as the test's result, so save the measure and run again to keep one.

What happens if I start a run while one is already going?

Only one model-wide run works per model at a time. Starting another joins the run that is already going instead of starting a second one.

Why does a test show "Never run"?

No stored result exists for it yet. A new test shows Never run until its first run finishes, and saving a change to a test clears its stored result, so it returns to Never run.

Why do some tests report as not run after a run finishes?

The run's scope held more tests than it covers. A run with dependents covers at most 50 tests, so the rest report as not run; run them in a smaller scope.

How long does a test run take?

A single run gets about one minute, and a run with dependents gets about two minutes for at most 50 tests.

Why did a run not update a test's stored result?

Two kinds of run leave no stored result: a run against unsaved SQL, and a run whose measure or test changed while it was going. Save the measure, then run again.

I deleted a measure. Are its tests gone?

No. A deleted measure hides its tests, and they come back when the measure is restored.

Who can create and run measure tests?

Creating and running tests, and reading run status, need edit access to the semantic model. If you can only view the model, you can see its tests but you cannot run them. See Who can do what in DataPrism.

Why did my test change not save?

If someone changed the test after you opened it, your save is refused as a version conflict. Reload to see their version, or overwrite it with yours. The refusal message is listed under When a test is refused.

Can I preview a measure before saving it?

Yes. The Preview pane runs the expression as it stands in the editor, saved or not. Running a preview does not save the measure.