Get Help

Test a Power BI Desktop file

Open the file in Power BI Desktop, tell CAT its name, write a DAX query. Nothing to install, nobody to ask — this is where testing a model before you publish it starts.

Prerequisites

Power BI Desktop on the machine where CAT runs, with the file open while the tests run. Windows only (Power BI Desktop is). No driver, no account, no permissions — the open file is reachable on the machine.

Add the data source

Data sources → New data source: a name, technology Power BI Desktop, and the name of the open file as Power BI Desktop shows it in its window title — Finance for Finance.pbix. Save. The test editor on the Tests page now runs DAX against the file.

Data sources:
- Name: finance model
  Provider: PowerBI@2
  Connection string: Finance   # the open file's name, without .pbix / .pbip

CAT finds the Analysis Services instance Power BI Desktop runs under the hood by itself. See PowerBI@2.

Write the first test

A smoke test — the table has rows:

Tests:
- Name: Account table is loaded
  Suite: Smoke tests
  Data source: finance model
  Query: EVALUATE 'Account'
  Expectation: set is not empty

And the one that pays off — the model agrees with the source it was built from. Both queries return one column, both ordered; the data sources may be different technologies:

Data sources:
- Name: finance model
  Provider: PowerBI@2
  Connection string: Finance
- Name: accounting
  Provider: SqlServer@2
  Connection string: "%ACCOUNTING_CONNECTION_STRING%"

Tests:
- Name: All states are in the model
  Suite: Model vs source
  First data source: finance model
  First query: |
    EVALUATE VALUES('Customer'[State])
    ORDER BY 'Customer'[State]
  Second data source: accounting
  Second query: SELECT StateName FROM dbo.States ORDER BY StateName
  Expectation: sets match

Where the DAX comes from when you do not want to write it: Get the DAX query behind a visual. More tests worth having — totals, measures per year with a tolerance, blank checks — on Test measures.

Good to know

  • The file must stay open while the tests run; close it and the next run ends with Error on every test of that data source.
  • Two files open at once are two data sources — each by its own name.
  • The same project file tests the published model later: swap the data source for a Dax@2 one, keep every test. See Test a semantic model in a workspace.