# Execute DAX Query — Microsoft Power BI

> Execute a DAX (Data Analysis Expressions) query against a Power BI dataset (semantic model). This is the primary analytics tool — use it to answer questions about values, aggregates, or filtered rows in a dataset. Use List Datasets first…

- Key: `microsoft_power_bi-execute-dax-query`
- Type: Action (Read-only)
- Version: 0.0.4
- App: Microsoft Power BI (`microsoft_power_bi`) — https://pipedream.com/apps/microsoft-power-bi.md
- This page (HTML): https://pipedream.com/apps/microsoft-power-bi/actions/execute-dax-query
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/microsoft_power_bi/actions/execute-dax-query/execute-dax-query.mjs

## Description

Execute a DAX (Data Analysis Expressions) query against a Power BI dataset (semantic model). This is the primary analytics tool — use it to answer questions about values, aggregates, or filtered rows in a dataset. Use **List Datasets** first to resolve a dataset name → `datasetId`. The query must be a single valid DAX expression starting with `EVALUATE`. **Table discovery (standard datasets):** For datasets published from Power BI Desktop, the REST `GET /datasets/{id}/tables` endpoint is scoped to push datasets only and will not list tables. Use `EVALUATE INFO.TABLES()` instead — it returns every table name in the semantic model. Typical agent flow: **List Workspaces** → **List Datasets** → **Execute DAX Query** (`EVALUATE INFO.TABLES()`) → **Execute DAX Query** (`EVALUATE 'TableName'`). Common patterns: • Discover all tables — `EVALUATE INFO.TABLES()` (use this before querying an unknown dataset) • List all rows of a table — `EVALUATE 'Species'` • Filter — `EVALUATE FILTER('Species', 'Species'[dietType] = "Carnivore")` • Top N by column — `EVALUATE TOPN(5, 'Species', 'Species'[weightKg], DESC)` • Aggregate single value — `EVALUATE ROW("Total", SUMX('Species', 'Species'[weightKg]))` • Peek at a table's columns — `EVALUATE TOPN(0, 'Species')` (returns an empty rowset with column names in the response). Limits: max 100,000 rows or 1,000,000 values per query, and `DEFINE`/multiple-statement queries are not supported via REST. The tenant must have 'Dataset Execute Queries REST API' enabled (admin setting) or the call returns 401/403. Pass `workspaceId` (from **List Workspaces**) or `workspaceName` to target a specific workspace, or omit both for My workspace. [See the documentation](https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries-in-group)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `datasetId` | `string` | Yes | ID of the dataset to query. Use List Datasets to find IDs by name. |
| `query` | `string` | Yes | A single DAX expression. Must start with EVALUATE. Example: EVALUATE FILTER('Species', 'Species'[dietType] = "Carnivore"). |
| `workspaceId` | `string` | No | ID of the workspace. Use the List Workspaces tool to see accessible workspaces. Omit to target My workspace. |
| `workspaceName` | `string` | No | Name of the workspace (alternative to Workspace ID). Use the List Workspaces tool to see accessible workspaces. |
| `includeNulls` | `boolean` | No | If true (default), null values are included in the response. Set to false for compacter output when nulls are not meaningful. |
| `impersonatedUserName` | `string` | No | UPN of an effective identity to use for Row-Level Security (RLS). Typically only needed for datasets with RLS roles configured. Example: someuser@mycompany.com |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "microsoft_power_bi",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "microsoft_power_bi-execute-dax-query",
  arguments: {
    datasetId: "Dataset ID",
    query: "DAX Query",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "microsoft_power_bi-execute-dax-query",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    microsoft_power_bi: { authProvisionId: "apn_xxxxxxx" },
    datasetId: "Dataset ID",
    query: "DAX Query",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "microsoft_power_bi-execute-dax-query",
    "configured_props": {
      "microsoft_power_bi": { "authProvisionId": "apn_xxxxxxx" },
      "datasetId": "Dataset ID",
      "query": "DAX Query"
    }
  }'
```

---

- App: https://pipedream.com/apps/microsoft-power-bi.md · All apps: https://pipedream.com/apps
