data-fetching

Fetch Power BI data in React components using the useSemanticModelQuery hook. Query results, caching, error handling, connection aliases.

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: data-fetching
description: Fetch Power BI data in React components using the useSemanticModelQuery hook. Query results, caching, error handling, connection aliases.
license: MIT
---

# Data Runtime (App Code Phase)

Generate React app code that fetches Power BI data at runtime using the
Fabric SDK. Queries should already be validated and saved as `.dax` files
(use the `data-discovery` skill for that).

## Data Fetching

- The `useSemanticModelQuery` hook (`src/hooks/use-semantic-model-query.ts`) is the primary way to fetch data in React components. It wraps the Fabric SDK client.
- The hook uses `getFabricClient()` internally — components should use the hook, not the client directly.
- For details on the SDK's caching behavior, error handling, and protocol options, see the `fabric-sdk` skill.

### Basic usage

```tsx
const query = 'EVALUATE SUMMARIZE(Sales, Products[Name], "Total", SUM(Sales[Amount]))'; // can also be the result of factory function
const { data, isLoading } = useSemanticModelQuery({
  connection: "salesModel",
  query: query,
});
```

### Result shape

The hook returns `data: CachedQueryResult | undefined`. Each query must
contain exactly one `EVALUATE` statement. On success:

```typescript
data.status         // "success"
data.table.columns  // Array<{ name: string, dataType: string }>
data.table.rows     // unknown[][] — row-major, values match column order
data.requestId      // string
data.fromCache      // boolean
data.cachedAt       // Date | undefined
```

**Important:** The SDK returns rows as arrays (`unknown[][]`), not objects.
Column names map to row positions by index. For example:
```typescript
// data.table.columns = [{ name: "Product[Name]", dataType: "String" },
//                       { name: "[Total]", dataType: "Int64" }]
// data.table.rows    = [["Widget", 42], ["Gadget", 17]]
//
// rows[0][0] = "Widget" corresponds to columns[0].name = "Product[Name]"
// rows[0][1] = 42      corresponds to columns[1].name = "[Total]"
```

### Handling errors

The SDK never throws — always check `result.status`:

```tsx
if (data?.status === "error") {
  // data.error.code, data.error.message
}
```

See the `fabric-sdk` skill for error categories and caching behavior of errors.

### Cache behavior

Results are cached by the SDK. Use `bypassCache` to force a fresh fetch:

```tsx
const { data } = useSemanticModelQuery({
  connection: "salesModel",
  query: 'EVALUATE ...',
  bypassCache: true,
});

// data.fromCache — true if served from SDK cache
// data.cachedAt — when the cached result was originally fetched
```

To clear cached results (e.g., after a data refresh or model change):

```tsx
import { clearQueryCache } from "@/hooks/use-semantic-model-query";

clearQueryCache();              // clear all models
clearQueryCache("salesModel");  // clear a specific model
```

See the `fabric-sdk` skill for full caching semantics (LRU eviction, what
gets cached, TTL patterns).

## Rules

- Never hardcode, mock, or store data — always fetch live from Power BI.
- Always use connection aliases from `fabric.yaml`, not raw dataset IDs.
- Surface query and service errors with meaningful UI messages.

More Performance skills

seo-audit

coreyhaines31/marketingskills

When the user wants to audit, review, or diagnose SEO issues on their site. Also use when the user mentions "SEO audit," "technical SEO," "why am I not ranking," "SEO issues," "on-page SEO," "meta tags review," "SEO health check," "my traffic dropped," "lost rankings," "not showing up in Google," "site isn't ranking," "Google update hit me," "page speed," "core web vitals," "crawl errors," or "indexing issues." Use this even if the user just says something vague like "my SEO is bad" or "help with SEO" — start with an audit. For building pages at scale to target keywords, see programmatic-seo. For adding structured data, see schema. For AI search optimization, see ai-seo.

195.1k

competitor-profiling

coreyhaines31/marketingskills

When the user wants to research, profile, or analyze competitors from their URLs. Also use when the user mentions 'competitor profile,' 'competitor research,' 'competitor analysis,' 'profile this competitor,' 'analyze competitor,' 'competitive intelligence,' 'competitor deep dive,' 'who are my competitors,' 'competitor landscape,' 'competitor dossier,' 'competitive audit,' or 'research these competitors.' Input is a list of competitor URLs. Output is structured competitor profile markdown files. For creating comparison/alternative pages from profiles, see competitors. For sales-specific battle cards, see sales-enablement.

65.8k

prospecting

coreyhaines31/marketingskills

When the user wants to find, qualify, and build a list of prospects to reach out to — across B2B SaaS, general B2B, or local small businesses. Also use when the user mentions "prospecting," "build a prospect list," "find prospects," "find leads," "lead gen list," "find SaaS companies that," "find B2B companies," "find local businesses," "ICP-fit accounts," "who should we go after," "outbound list," "target account list," "find clients near me," "businesses without websites," "prospect research," "qualified leads," "find my first customers," "early adopters," "design partners," "beta users," or "who has this problem." Use this for the list-building and qualification phase. For writing the outbound copy after the list is built, see cold-email. For deep competitive research on specific accounts, see competitor-profiling.

42.1k

← All Performance skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY