---
title: "Test a semantic model in a workspace"
description: "Test a semantic model published to a Power BI or Microsoft Fabric workspace — XMLA endpoint, service principal, the connection string; Azure and SQL Server Analysis Services the same way"
url: "https://docs.justcat.it/how-to-guides/data-platforms/power-bi/test-a-semantic-model-in-a-workspace/"
---
# Test a semantic model in a workspace


## Prerequisites

* The workspace is on a capacity that exposes the **XMLA endpoint**: Power BI Premium, Premium Per User, or a Fabric capacity. Read access through the endpoint is on by default; the tenant setting *Allow XMLA endpoints and Analyze in Excel with on-premises semantic models* must be enabled (it is, unless an admin turned it off).
* An identity that may read the model. For unattended runs that is a **service principal** — an app registration with a secret in Microsoft Entra ID. Your Power BI administrator does the one-time part: allow service principals to use Power BI APIs (tenant setting, usually scoped to a security group), then add the principal to the workspace with at least the **Member** role — Viewer is not enough for the endpoint. Microsoft's walk-through: <a href="https://learn.microsoft.com/en-us/power-bi/enterprise/service-premium-service-principal" target="_blank">Automate Premium workspace and semantic model tasks with service principals</a>.
* The workspace connection URL: workspace **Settings → Premium → Workspace Connection → Copy**; it looks like `powerbi://api.powerbi.com/v1.0/myorg/Sales%20Workspace`.

## Add the data source


**CAT Studio**


**Data sources → New data source**: a name, technology *Power BI Semantic Model* (or *MS Fabric Semantic Model* — identical underneath), then the workspace connection URL, the model's name, and the service principal as user and password — **typed as `%NAME%` environment-variable references**, never as the values. Studio writes the connection string for you.


**YAML**


```yaml
Data sources:
- Name: sales model
  Provider: Dax@2
  Connection string: >
    Data Source=powerbi://api.powerbi.com/v1.0/myorg/Sales%20Workspace;
    Initial Catalog=Sales;
    User ID=%PBI_SP_USER%;
    Password=%PBI_SP_SECRET%;
```

`PBI_SP_USER` holds `app:<application id>@<tenant id>`, `PBI_SP_SECRET` the secret — see [Work with secrets](https://docs.justcat.it/how-to-guides/organize-and-run-tests/work-with-secrets/ "Work with secrets"). The whole string may also be one variable. Every key: [Dax@2](https://docs.justcat.it/reference/data-sources/providers/dax-2/ "Dax@2").




### Azure Analysis Services, SQL Server Analysis Services

Same provider, same tests; only `Data Source` changes — the `asazure://…` address for Azure Analysis Services (service principal the same way), the server name for SSAS, where a local instance takes `Integrated Security=SSPI` and no principal at all. Studio: technology *Azure Analysis Services* or *SQL Server Analysis Services*.

## Write the tests

Exactly the tests of a Desktop file — a model is a model. Start from the project you used while building the file and swap the data source:


**Properties**



Name
: Sales per year match the warehouse

Suite
: Model vs source

First data source
: sales model

First query
: ```
  EVALUATE SUMMARIZECOLUMNS('Date'[Year], "Sales", [Total Sales])
  ORDER BY 'Date'[Year]
  ```

Second data source
: DWH

Second query
: SELECT YEAR(OrderDate), SUM(Amount) FROM fact.Sales GROUP BY YEAR(OrderDate) ORDER BY 1

Expectation
: sets match

Key
: 1

Tolerance
: 0.01





**YAML**


```yaml
Tests:
- Name: Sales per year match the warehouse
  Suite: Model vs source
  First data source: sales model
  First query: |
    EVALUATE SUMMARIZECOLUMNS('Date'[Year], "Sales", [Total Sales])
    ORDER BY 'Date'[Year]
  Second data source: DWH
  Second query: SELECT YEAR(OrderDate), SUM(Amount) FROM fact.Sales GROUP BY YEAR(OrderDate) ORDER BY 1
  Expectation: sets match
  Key: 1
  Tolerance: 0.01
```




More on [Test measures](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/test-measures/ "Test measures"); the DAX without writing it: [Get the DAX query behind a visual](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/get-the-dax-query-behind-a-visual/ "Get the DAX query behind a visual").

## Without a service principal

Your own account works for an interactive session — `Authentication` left to the driver prompts you, MFA included — and it works only there: CAT opens more than one connection, so you confirm more than once, and an unattended run has nobody to confirm. Use it to try things; use the service principal for anything scheduled.

## Related

* [Test Power BI](https://docs.justcat.it/how-to-guides/data-platforms/power-bi/test-power-bi/ "Test Power BI") — the overview.
* [Dax@2](https://docs.justcat.it/reference/data-sources/providers/dax-2/ "Dax@2") — the provider, all connection-string forms.
* [Test Microsoft Fabric](https://docs.justcat.it/how-to-guides/data-platforms/test-microsoft-fabric/ "Test Microsoft Fabric") — the Fabric semantic model is this page; the lakehouse and warehouse are there.

