powerbi-authoring-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Update Check — ONCE PER SESSION (mandatory) The first time this skill is used in a session, run the check-updates skill before proceeding.
  • GitHub Copilot CLI / VS Code: invoke the
    check-updates
    skill.
  • Claude Code / Cowork / Cursor / Windsurf / Codex: compare local vs remote package.json version.
  • Skip if the check was already performed earlier in this session.
CRITICAL NOTES
  1. To find the workspace details (including its ID) from workspace name: list all workspaces and, then, use JMESPath filtering
  2. To find the item details (including its ID) from workspace ID, item type, and item name: list all items of that type in that workspace and, then, use JMESPath filtering
更新检查 — 每会话一次(必填) 在会话中首次使用此技能前,请先运行check-updates技能。
  • GitHub Copilot CLI / VS Code:调用
    check-updates
    技能。
  • Claude Code / Cowork / Cursor / Windsurf / Codex:比较本地与远程package.json版本。
  • 若会话早期已执行过该检查,可跳过。
重要说明
  1. 从工作区名称查找工作区详情(包括其ID):列出所有工作区,然后使用JMESPath筛选
  2. 从工作区ID、项类型和项名称查找项详情(包括其ID):列出该工作区中该类型的所有项,然后使用JMESPath筛选

Power BI Semantic Model Authoring — CLI Skill

Power BI语义模型创作 — CLI技能

Table of Contents

目录

TaskReferenceNotes
Finding Workspaces and Items in FabricCOMMON-CLI.md § Finding Workspaces and Items in FabricMandatoryREAD link first [needed for finding workspace id by its name or item id by its name, item type, and workspace id]
Fabric Topology & Key ConceptsCOMMON-CORE.md § Fabric Topology & Key ConceptsHierarchy; Finding Things in Fabric
Environment URLsCOMMON-CORE.md § Environment URLsProduction (Public Cloud)
Tool Selection RationaleCOMMON-CLI.md § Tool Selection Rationale
Authentication RecipesCOMMON-CLI.md § Authentication Recipes
az login
flows, environment detection, token acquisition, and debugging
Fabric Control-Plane API via
az rest
COMMON-CLI.md § Fabric Control-Plane API via
az rest
Always pass
--resource
; includes workspace/item operations, pagination, and LRO patterns
OneLake Data Access via
curl
COMMON-CLI.md § OneLake Data Access via
curl
Use
curl
not
az rest
(different token audience)
Job Execution (CLI)COMMON-CLI.md § Job ExecutionRun notebooks/pipelines, refresh semantic models, check/cancel jobs
OneLake ShortcutsCOMMON-CLI.md § OneLake ShortcutsCreate a Shortcut; List Shortcuts; Delete a Shortcut
Capacity Management (CLI)COMMON-CLI.md § Capacity ManagementList Capacities; Assign Workspace to Capacity
Composite RecipesCOMMON-CLI.md § Composite RecipesEnd-to-end workspace→lakehouse→file, SQL endpoint→query, and notebook execution recipes
Gotchas & Troubleshooting (CLI-Specific)COMMON-CLI.md § Gotchas & Troubleshooting (CLI-Specific)
az rest
audience, shell escaping, token expiry
Quick ReferenceCOMMON-CLI.md § Quick Reference
az rest
Template; Token Audience ↔ CLI Tool Matrix
DAX Queries & Metadata Discoverypowerbi-consumption-cliRead-only DAX queries; use for post-creation validation
Tool StackSKILL.md § Tool Stack
az rest
(primary),
jq
(JSON parsing),
base64
encoding
Authentication & API AudiencesSKILL.md § Authentication & API AudiencesTwo audiences: Fabric API vs Power BI Datasets API
Must/Prefer/AvoidSKILL.md § Must/Prefer/AvoidGuardrails for semantic model authoring
SemanticModel Definition & EnvelopeITEM-DEFINITIONS-CORE.md § SemanticModelTMDL format; required parts, envelope structure, support matrix
TMDL File Structure & ExamplesSKILL.md § TMDL File StructureRequired parts, minimal content examples
TMDL CRUD (Create / Get / Update)SKILL.md § Create Semantic ModelCreateGet/DownloadUpdate; full lifecycle with LRO
Authoring Scope MatrixSKILL.md § Authoring Scope MatrixWhat Fabric API supports vs what to avoid
Refresh OperationsSKILL.md § Refresh OperationsTrigger, cancel, history, schedule (Power BI API)
Data Sources & ParametersSKILL.md § Data Sources & ParametersGet/update data sources and parameters
PermissionsSKILL.md § PermissionsGrant/update dataset user permissions
Deployment PipelinesSKILL.md § Deployment PipelinesList, get stages, deploy between stages
Agentic WorkflowSKILL.md § Agentic WorkflowStep-by-step: discover → create → verify → refresh → validate
TroubleshootingSKILL.md § TroubleshootingCommon errors table: LRO, auth, TMDL encoding, refresh
ExamplesSKILL.md § ExamplesCreate model, download definition, refresh, deploy
Property-to-API Mappingsemantic-model-properties-guide.md § Property-to-API MappingMaps each property category to the correct API surface
Owner, Storage Mode & Operational Metadatasemantic-model-properties-guide.md § Owner, Storage ModePower BI Datasets API properties
Refresh History Response Propertiessemantic-model-properties-guide.md § Refresh HistoryRefresh detail response fields
Data Source Response Propertiessemantic-model-properties-guide.md § Data SourcesConnection and gateway properties
DirectQuery / LiveConnection Refresh Schedulesemantic-model-properties-guide.md § DQ Refresh ScheduleDirectQuery/LiveConnection schedule settings
Upstream Dataflow Linkssemantic-model-properties-guide.md § Upstream DataflowsDataflow dependency properties
Per-Table Storage Modesemantic-model-properties-guide.md § Per-Table StorageTable-level storage mode via TMDL
TMDL Syntax Rulestmdl-authoring-guide.md § TMDL Syntax RulesTab indentation, object declaration, quoting rules
Modeling Best Practicestmdl-authoring-guide.md § Modeling Best PracticesNaming conventions, column rules, measure & DAX rules, format strings
Relationshipstmdl-authoring-guide.md § RelationshipsRelationship declarations, key rules
Hierarchiestmdl-authoring-guide.md § HierarchiesHierarchy declarations and key rules
Direct Lake Guidelinestmdl-authoring-guide.md § Direct Lake GuidelinesDirect Lake mode configuration and constraints
Calculated Tablestmdl-authoring-guide.md § Calculated TablesDAX-based calculated table definitions
Date/Calendar Tabletmdl-authoring-guide.md § Date/Calendar TableCalendar table setup and marking
Parameterstmdl-authoring-guide.md § ParametersExpression-based parameter declarations
Annotationstmdl-authoring-guide.md § AnnotationsModel and object-level annotations
TMDL File Layout & Core Filestmdl-advanced-features-guide.md § File LayoutDirectory structure, database.tmdl, model.tmdl
Calculation Groupstmdl-advanced-features-guide.md § Calculation GroupsCalculation group tables and items
Security Rolestmdl-advanced-features-guide.md § Security RolesRLS/OLS role definitions
Security Role MembershipsSKILL.md § Security Role MembershipsAdd/list/delete users & groups in RLS roles (Power BI API)
Translations / Culturestmdl-advanced-features-guide.md § Translations / CulturesLocalization via culture files
Perspectivestmdl-advanced-features-guide.md § PerspectivesPerspective definitions for subset views
Functionstmdl-advanced-features-guide.md § FunctionsUser-defined DAX functions in the model
Calendar Objectstmdl-advanced-features-guide.md § Calendar ObjectsAuto date/time calendar table objects

任务参考文档说明
在Fabric中查找工作区和项COMMON-CLI.md § 在Fabric中查找工作区和项必填 — 先阅读链接内容[需要通过工作区名称查找工作区ID,或通过项名称、项类型和工作区ID查找项ID]
Fabric拓扑与核心概念COMMON-CORE.md § Fabric拓扑与核心概念层级结构;在Fabric中查找资源
环境URLCOMMON-CORE.md § 环境URL生产环境(公有云)
工具选择依据COMMON-CLI.md § 工具选择依据
身份验证方案COMMON-CLI.md § 身份验证方案
az login
流程、环境检测、令牌获取和调试
通过
az rest
调用Fabric控制平面API
COMMON-CLI.md § 通过
az rest
调用Fabric控制平面API
必须传递
--resource
参数
;包括工作区/项操作、分页和LRO模式
通过
curl
访问OneLake数据
COMMON-CLI.md § 通过
curl
访问OneLake数据
使用
curl
而非
az rest
(令牌受众不同)
作业执行(CLI)COMMON-CLI.md § 作业执行运行笔记本/流水线、刷新语义模型、检查/取消作业
OneLake快捷方式COMMON-CLI.md § OneLake快捷方式创建快捷方式;列出快捷方式;删除快捷方式
容量管理(CLI)COMMON-CLI.md § 容量管理列出容量;为工作区分配容量
复合方案COMMON-CLI.md § 复合方案从工作区到湖仓再到文件、SQL端点查询、笔记本执行的端到端方案
常见问题与故障排除(CLI专属)COMMON-CLI.md § 常见问题与故障排除(CLI专属)
az rest
受众、shell转义、令牌过期
快速参考COMMON-CLI.md § 快速参考
az rest
模板;令牌受众与CLI工具矩阵
DAX查询与元数据发现powerbi-consumption-cli只读DAX查询;用于创建后的验证
工具栈SKILL.md § 工具栈
az rest
(主要工具)、
jq
(JSON解析)、
base64
编码
身份验证与API受众SKILL.md § 身份验证与API受众两个受众:Fabric API与Power BI Datasets API
必须/推荐/避免SKILL.md § 必须/推荐/避免语义模型创作的约束规则
语义模型定义与信封结构ITEM-DEFINITIONS-CORE.md § 语义模型TMDL格式;必填部分、信封结构支持矩阵
TMDL文件结构与示例SKILL.md § TMDL文件结构必填部分、最小内容示例
TMDL增删改查(创建/获取/更新)SKILL.md § 创建语义模型创建获取/下载更新;包含LRO的完整生命周期
创作范围矩阵SKILL.md § 创作范围矩阵Fabric API支持的操作与需避免的操作
刷新操作SKILL.md § 刷新操作触发、取消、历史记录、调度(Power BI API)
数据源与参数SKILL.md § 数据源与参数获取/更新数据源和参数
权限SKILL.md § 权限授予/更新数据集用户权限
部署流水线SKILL.md § 部署流水线列出流水线、获取阶段、在阶段间部署
智能工作流SKILL.md § 智能工作流分步流程:发现 → 创建 → 验证 → 刷新 → 校验
故障排除SKILL.md § 故障排除常见错误表:LRO、身份验证、TMDL编码、刷新
示例SKILL.md § 示例创建模型、下载定义、刷新、部署
属性到API的映射semantic-model-properties-guide.md § 属性到API的映射将每个属性类别映射到正确的API层面
所有者、存储模式与操作元数据semantic-model-properties-guide.md § 所有者、存储模式Power BI Datasets API属性
刷新历史响应属性semantic-model-properties-guide.md § 刷新历史刷新详情响应字段
数据源响应属性semantic-model-properties-guide.md § 数据源连接和网关属性
DirectQuery / LiveConnection刷新调度semantic-model-properties-guide.md § DQ刷新调度DirectQuery/LiveConnection调度设置
上游数据流链接semantic-model-properties-guide.md § 上游数据流数据流依赖属性
按表存储模式semantic-model-properties-guide.md § 按表存储通过TMDL设置表级存储模式
TMDL语法规则tmdl-authoring-guide.md § TMDL语法规则制表符缩进、对象声明、引号规则
建模最佳实践tmdl-authoring-guide.md § 建模最佳实践命名规范、列规则、度量值与DAX规则、格式字符串
关系tmdl-authoring-guide.md § 关系关系声明、键规则
层次结构tmdl-authoring-guide.md § 层次结构层次结构声明与键规则
Direct Lake指南tmdl-authoring-guide.md § Direct Lake指南Direct Lake模式配置与约束
计算表tmdl-authoring-guide.md § 计算表基于DAX的计算表定义
日期/日历表tmdl-authoring-guide.md § 日期/日历表日历表设置与标记
参数tmdl-authoring-guide.md § 参数基于表达式的参数声明
注释tmdl-authoring-guide.md § 注释模型和对象级注释
TMDL文件布局与核心文件tmdl-advanced-features-guide.md § 文件布局目录结构、database.tmdlmodel.tmdl
计算组tmdl-advanced-features-guide.md § 计算组计算组表和项
安全角色tmdl-advanced-features-guide.md § 安全角色RLS/OLS角色定义
安全角色成员SKILL.md § 安全角色成员在RLS角色中添加/列出/删除用户和组(Power BI API)
翻译/区域设置tmdl-advanced-features-guide.md § 翻译/区域设置通过区域设置文件实现本地化
透视tmdl-advanced-features-guide.md § 透视子集视图的透视定义
函数tmdl-advanced-features-guide.md § 函数模型中的用户自定义DAX函数
日历对象tmdl-advanced-features-guide.md § 日历对象自动日期/时间日历表对象

Tool Stack

工具栈

ToolRoleInstall
az
CLI
Primary:
az rest
for Fabric and Power BI REST API calls,
az login
for auth.
Pre-installed in most dev environments
jq
Parse JSON from
az rest
responses
Pre-installed or trivial
base64
(Linux/macOS) /
[Convert]::ToBase64String
(PowerShell)
Encode TMDL file content for definition payloadsBuilt-in
Agent check — verify before first operation:
bash
az version 2>/dev/null || echo "INSTALL: https://learn.microsoft.com/cli/azure/install-azure-cli"

工具作用安装方式
az
CLI
主要工具
az rest
用于调用Fabric和Power BI REST API,
az login
用于身份验证。
多数开发环境已预装
jq
解析
az rest
响应的JSON数据
已预装或易于安装
base64
(Linux/macOS)/
[Convert]::ToBase64String
(PowerShell)
为定义负载编码TMDL文件内容内置工具
智能检查 — 首次操作前验证:
bash
az version 2>/dev/null || echo "安装地址:https://learn.microsoft.com/cli/azure/install-azure-cli"

Authentication & API Audiences

身份验证与API受众

This skill uses two distinct API audiences. Using the wrong audience returns a 401.
APIAudience (
--resource
)
Use For
Fabric Items API
https://api.fabric.microsoft.com
Create/get/update/delete semantic model definitions, list items, LRO polling
Power BI Datasets API
https://analysis.windows.net/powerbi/api
Refresh, data sources, parameters, permissions, deployment pipelines
bash
undefined
本技能使用两个不同的API受众。使用错误的受众会返回401错误。
API受众(
--resource
参数)
用途
Fabric Items API
https://api.fabric.microsoft.com
创建/获取/更新/删除语义模型定义、列出项、轮询LRO
Power BI Datasets API
https://analysis.windows.net/powerbi/api
刷新、数据源、参数、权限、部署流水线
bash
undefined

Fabric Items API — semantic model definition operations

Fabric Items API — 语义模型定义操作

Power BI Datasets API — refresh, data sources, permissions

Power BI Datasets API — 刷新、数据源、权限操作

Must/Prefer/Avoid

必须/推荐/避免

MUST DO

必须执行

  • Read the relevant TMDL reference sections BEFORE generating any TMDL — at minimum read TMDL Syntax Rules and Modeling Best Practices. If the task involves relationships, hierarchies, calculation groups, security roles, or translations, also read the corresponding sections in tmdl-authoring-guide.md and tmdl-advanced-features-guide.md. Do not generate TMDL from memory.
  • Always pass
    --resource
    to
    az rest
    — omitting it causes silent auth failures. Use the correct audience per the table above.
  • Always pass
    --headers "Content-Type=application/json"
    on POST/PATCH/PUT calls with a
    --body
    to the Power BI Datasets API — omitting it causes
    Unsupported Media Type
    errors.
  • Include ALL definition parts in
    updateDefinition
    — modified + unmodified. The API replaces the entire definition; omitting parts deletes them.
  • Never include
    .platform
    in
    updateDefinition
    payloads — it is Git integration metadata and causes errors.
  • Poll LRO to completion
    createItemWithDefinition
    ,
    getDefinition
    , and
    updateDefinition
    return
    202 Accepted
    with an
    Operation-Id
    header. Poll until terminal state.
  • Base64-encode TMDL content — all
    payload
    values in definition parts must be base64-encoded.
  • Single-quote names with special chars — names containing spaces,
    .
    ,
    =
    ,
    :
    , or
    '
    must be wrapped in single quotes in TMDL.
  • Verify workspace has capacity before creating a semantic model — call
    GET /v1/workspaces/{id}
    and check
    capacityId
    .
  • 生成任何TMDL之前,请先阅读相关的TMDL参考章节 — 至少阅读TMDL语法规则建模最佳实践。若任务涉及关系、层次结构、计算组、安全角色或翻译,还需阅读tmdl-authoring-guide.mdtmdl-advanced-features-guide.md中的对应章节。切勿凭记忆生成TMDL。
  • 始终为
    az rest
    传递
    --resource
    参数
    — 省略该参数会导致静默身份验证失败。根据上表使用正确的受众。
  • 对包含
    --body
    的POST/PATCH/PUT调用,始终为Power BI Datasets API传递
    --headers "Content-Type=application/json"
    — 省略该参数会导致“不支持的媒体类型”错误。
  • updateDefinition
    中包含所有定义部分
    — 修改后的部分+未修改的部分。API会替换整个定义;省略的部分会被删除。
  • 切勿在
    updateDefinition
    负载中包含
    .platform
    — 这是Git集成元数据,会导致错误。
  • 轮询LRO直至完成
    createItemWithDefinition
    getDefinition
    updateDefinition
    会返回
    202 Accepted
    状态码及
    Operation-Id
    响应头。需轮询直至达到最终状态。
  • 对TMDL内容进行Base64编码 — 定义部分中所有
    payload
    值必须进行Base64编码。
  • 为包含特殊字符的名称添加单引号 — 包含空格、
    .
    =
    :
    '
    的名称,在TMDL中必须用单引号包裹。
  • 创建语义模型前验证工作区是否有容量 — 调用
    GET /v1/workspaces/{id}
    并检查
    capacityId
    字段。

PREFER

推荐做法

  • createItemWithDefinition
    (single POST) over create-then-update for new semantic models.
  • TMDL format over TMSL — TMDL is text-based, diff-friendly, and the preferred format for Fabric.
  • Measures before columns in TMDL table files — follows TMDL convention.
  • Multi-line DAX in triple backticks — improves readability for complex expressions.
  • Route fine-grained changes to
    powerbi-modeling-mcp
    — for adding/modifying individual measures, columns, or relationships, the MCP server is more efficient than full definition round-trips.
  • Get definition before updating — always retrieve the current definition, modify, then POST back to avoid overwriting concurrent changes.
  • Cross-reference
    powerbi-consumption-cli
    for post-creation validation — run DAX queries to verify measures, relationships, and data.
  • 使用
    createItemWithDefinition
    (单次POST请求)而非先创建再更新的方式来新建语义模型。
  • 优先使用TMDL格式而非TMSL — TMDL是基于文本的格式,支持差异对比,是Fabric推荐的格式。
  • 在TMDL表文件中先写度量值再写列 — 遵循TMDL约定。
  • 在三重反引号中编写多行DAX — 提升复杂表达式的可读性。
  • 将细粒度更改路由至
    powerbi-modeling-mcp
    — 对于添加/修改单个度量值、列或关系,MCP服务器比完整定义往返更高效。
  • 更新前先获取定义 — 始终检索当前定义,修改后再POST回去,避免覆盖并发更改。
  • **交叉引用
    powerbi-consumption-cli
    **进行创建后的验证 — 运行DAX查询来验证度量值、关系和数据。

AVOID

避免操作

  • updateDefinition
    for small changes
    — a full definition round-trip is heavy; route to
    powerbi-modeling-mcp
    for individual object edits.
  • Report creation — not supported by this skill. Reports require a separate definition format (PBIR/PBIR-Legacy).
  • lineageTag
    on new objects
    — TMDL auto-generates lineage tags; adding them manually causes conflicts.
  • //
    comments in TMDL
    — not supported. Use
    ///
    descriptions instead.
  • description
    property in TMDL
    — use
    ///
    syntax above the object instead.
  • Hardcoded workspace/item IDs — resolve dynamically via REST API (see COMMON-CLI.md § Finding Workspaces and Items in Fabric).
  • Sending only modified parts in
    updateDefinition
    — the API replaces the full definition; missing parts are deleted.

  • 对小更改使用
    updateDefinition
    — 完整定义往返开销大;对单个对象编辑请使用
    powerbi-modeling-mcp
  • 创建报表 — 本技能不支持报表创建。报表需要单独的定义格式(PBIR/PBIR-Legacy)。
  • 在新对象上添加
    lineageTag
    — TMDL会自动生成 lineage标签;手动添加会导致冲突。
  • 在TMDL中使用
    //
    注释
    — 不支持该语法,请使用
    ///
    描述。
  • 在TMDL中使用
    description
    属性
    — 请在对象上方使用
    ///
    语法。
  • 硬编码工作区/项ID — 通过REST API动态解析(请参阅COMMON-CLI.md § 在Fabric中查找工作区和项)。
  • updateDefinition
    中仅发送修改的部分
    — API会替换整个定义;缺失的部分会被删除。

TMDL File Structure

TMDL文件结构

For the full definition envelope and part paths, see ITEM-DEFINITIONS-CORE.md § SemanticModel.
Required TMDL parts for
createItemWithDefinition
and
updateDefinition
:
Part PathContentRequired
definition.pbism
Semantic model connection settingsYes
definition/database.tmdl
Database properties (compatibility level)Yes
definition/model.tmdl
Model properties (culture, default summarization)Yes
definition/tables/<TableName>.tmdl
Per-table: columns, measures, partitionsYes (≥1)
Critical:
updateDefinition
must include ALL parts — modified and unmodified. The API replaces the entire definition. Never include
.platform
in update payloads.
For TMDL syntax rules, naming conventions, and modeling best practices, see tmdl-authoring-guide.md.

完整的定义信封和部分路径,请参阅ITEM-DEFINITIONS-CORE.md § 语义模型
createItemWithDefinition
updateDefinition
所需的TMDL部分:
部分路径内容是否必填
definition.pbism
语义模型连接设置
definition/database.tmdl
数据库属性(兼容级别)
definition/model.tmdl
模型属性(区域设置、默认汇总方式)
definition/tables/<TableName>.tmdl
按表:列、度量值、分区是(至少1个)
重要提示
updateDefinition
必须包含所有部分 — 修改的和未修改的。API会替换整个定义。更新负载中切勿包含
.platform
TMDL语法规则、命名规范和建模最佳实践,请参阅tmdl-authoring-guide.md

Minimal TMDL Content Examples

最小TMDL内容示例

definition.pbism

definition.pbism

json
{
    "version": "4.2",
    "settings": {
        "qnaEnabled": true
    }
}
json
{
    "version": "4.2",
    "settings": {
        "qnaEnabled": true
    }
}

database.tmdl

database.tmdl

tmdl
database
	compatibilityLevel: 1702
	compatibilityMode: powerBI
tmdl
database
	compatibilityLevel: 1702
	compatibilityMode: powerBI

model.tmdl

model.tmdl

tmdl
model Model
	culture: en-US
	defaultPowerBIDataSourceVersion: powerBI_V3
	discourageImplicitMeasures
Note:
defaultPowerBIDataSourceVersion: powerBI_V3
is required for Import-mode models. Without it, the API returns
Import from JSON supported for V3 models only
.
tmdl
model Model
	culture: en-US
	defaultPowerBIDataSourceVersion: powerBI_V3
	discourageImplicitMeasures
注意:对于导入模式模型,
defaultPowerBIDataSourceVersion: powerBI_V3
是必填项。缺失该参数会导致API返回“仅V3模型支持从JSON导入”错误。

Import-Mode Table

导入模式表

tmdl
table Customer

	/// Total number of customers
	measure '# Customers' = COUNTROWS(Customer)
		formatString: #,##0

	column CustomerId
		dataType: int64
		isHidden
		isKey
		summarizeBy: none
		sourceColumn: CustomerId

	column 'Customer Name'
		dataType: string
		sourceColumn: CustomerName

	partition Customer = m
		mode: import
		source =
			let
				Source = Sql.Database(#"Server", #"Database"),
				Customer = Source{[Schema="dbo", Item="Customer"]}[Data]
			in
				Customer
tmdl
table Customer

	/// 客户总数
	measure '# Customers' = COUNTROWS(Customer)
		formatString: #,##0

	column CustomerId
		dataType: int64
		isHidden
		isKey
		summarizeBy: none
		sourceColumn: CustomerId

	column 'Customer Name'
		dataType: string
		sourceColumn: CustomerName

	partition Customer = m
		mode: import
		source =
			let
				Source = Sql.Database(#"Server", #"Database"),
				Customer = Source{[Schema="dbo", Item="Customer"]}[Data]
			in
				Customer

Direct Lake Table

Direct Lake表

tmdl
expression DL_Lakehouse =
	let
		Source = AzureStorage.DataLake("https://onelake.dfs.fabric.microsoft.com/<WorkspaceId>/<LakehouseId>", [HierarchicalNavigation=true])
	in
		Source

table Sales

	/// Total revenue
	measure 'Total Sales' = ```
			SUMX(
				Sales,
				Sales[Quantity] * Sales[UnitPrice]
			)
			```
		formatString: \$#,##0.00

	column SalesKey
		dataType: int64
		isHidden
		isKey
		summarizeBy: none
		sourceColumn: sales_key

	column Quantity
		dataType: int64
		sourceColumn: quantity

	column UnitPrice
		dataType: decimal
		summarizeBy: none
		sourceColumn: unit_price

	partition Sales = entity
		mode: directLake
		source
			entityName: Sales
			schemaName: dbo
			expressionSource: DL_Lakehouse

tmdl
expression DL_Lakehouse =
	let
		Source = AzureStorage.DataLake("https://onelake.dfs.fabric.microsoft.com/<WorkspaceId>/<LakehouseId>", [HierarchicalNavigation=true])
	in
		Source

table Sales

	/// 总销售额
	measure 'Total Sales' = ```
			SUMX(
				Sales,
				Sales[Quantity] * Sales[UnitPrice]
			)
			```
		formatString: \$#,##0.00

	column SalesKey
		dataType: int64
		isHidden
		isKey
		summarizeBy: none
		sourceColumn: sales_key

	column Quantity
		dataType: int64
		sourceColumn: quantity

	column UnitPrice
		dataType: decimal
		summarizeBy: none
		sourceColumn: unit_price

	partition Sales = entity
		mode: directLake
		source
			entityName: Sales
			schemaName: dbo
			expressionSource: DL_Lakehouse

Create Semantic Model

创建语义模型

Full lifecycle: author TMDL → base64-encode → construct payload → POST → poll LRO.
Per COMMON-CLI.md § Item CRUD Operations and ITEM-DEFINITIONS-CORE.md § Definition Envelope:
bash
WS_ID="<workspaceId>"
完整生命周期:创作TMDL → Base64编码 → 构造请求体 → POST请求 → 轮询LRO(长时间运行操作)。
请参阅COMMON-CLI.md § 项CRUD操作ITEM-DEFINITIONS-CORE.md § 定义信封
bash
WS_ID="<workspaceId>"

1. Base64-encode each TMDL file

1. 对每个TMDL文件进行Base64编码

PBISM=$(base64 -w 0 < definition.pbism) DB=$(base64 -w 0 < definition/database.tmdl) MODEL=$(base64 -w 0 < definition/model.tmdl) TABLE=$(base64 -w 0 < definition/tables/Customer.tmdl)
PBISM=$(base64 -w 0 < definition.pbism) DB=$(base64 -w 0 < definition/database.tmdl) MODEL=$(base64 -w 0 < definition/model.tmdl) TABLE=$(base64 -w 0 < definition/tables/Customer.tmdl)

2. Construct payload and create — use --verbose to capture HTTP status and LRO headers

2. 构造负载并创建 — 使用--verbose参数捕获HTTP状态和LRO响应头

cat > /tmp/body.json << EOF { "displayName": "MySalesModel", "definition": { "format": "TMDL", "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$TABLE", "payloadType": "InlineBase64"} ] } } EOF az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> **PowerShell** — use `[Convert]::ToBase64String([System.IO.File]::ReadAllBytes("file"))` instead of `base64 -w 0`.

If the response is `202 Accepted`, poll using the LRO pattern from [COMMON-CLI.md § Long-Running Operations](../../common/COMMON-CLI.md#long-running-operations-lro-pattern).

---
cat > /tmp/body.json << EOF { "displayName": "MySalesModel", "definition": { "format": "TMDL", "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$TABLE", "payloadType": "InlineBase64"} ] } } EOF az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> **PowerShell环境** — 使用`[Convert]::ToBase64String([System.IO.File]::ReadAllBytes("file"))`替代`base64 -w 0`。

如果响应为`202 Accepted`,请按照[COMMON-CLI.md § 长时间运行操作](../../common/COMMON-CLI.md#long-running-operations-lro-pattern)中的LRO模式进行轮询。

---

Get/Download Definition

获取/下载定义

Retrieve TMDL definition for backup, migration, or inspection.
getDefinition
is a POST (not GET).
bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"
检索TMDL定义用于备份、迁移或检查。
getDefinition
POST请求(而非GET)。
bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"

1. Request definition — may return 200 (inline) or 202 (LRO)

1. 请求定义 — 可能返回200(内联结果)或202(LRO)

RESPONSE=$(az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels/$MODEL_ID/getDefinition?format=TMDL"
--body '{}'
--output json 2>/dev/null)
RESPONSE=$(az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels/$MODEL_ID/getDefinition?format=TMDL"
--body '{}'
--output json 2>/dev/null)

2. If 202, poll the Location header URL until Succeeded, then GET /result

2. 如果返回202,轮询Location响应头中的URL直至状态为Succeeded,然后GET /result

3. Decode each part

3. 解码每个部分

echo "$RESPONSE" | jq -r '.definition.parts[] | .path + " " + .payload' |
while read -r path payload; do mkdir -p "$(dirname "$path")" echo "$payload" | base64 -d > "$path" done

---
echo "$RESPONSE" | jq -r '.definition.parts[] | .path + " " + .payload' |
while read -r path payload; do mkdir -p "$(dirname "$path")" echo "$payload" | base64 -d > "$path" done

---

Update Definition

更新定义

Critical rules: Must include ALL parts (modified + unmodified). Never include
.platform
. The API replaces the entire definition — omitted parts are deleted.
bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"
重要规则:必须包含所有部分(修改的+未修改的)。切勿包含
.platform
。API会替换整个定义 — 省略的部分会被删除。
bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"

1. Get current definition (see Get/Download Definition above)

1. 获取当前定义(请参阅上方的获取/下载定义)

2. Modify the relevant TMDL files

2. 修改相关TMDL文件

3. Re-encode ALL parts and POST

3. 对所有部分重新编码并POST

cat > /tmp/body.json << EOF { "definition": { "format": "TMDL", "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$TABLE", "payloadType": "InlineBase64"} ] } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels/$MODEL_ID/updateDefinition"
--body @/tmp/body.json

Use `?updateMetadata=true` query parameter only when the `.platform` file must be included to update display name or description via definition.

---
cat > /tmp/body.json << EOF { "definition": { "format": "TMDL", "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$TABLE", "payloadType": "InlineBase64"} ] } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels/$MODEL_ID/updateDefinition"
--body @/tmp/body.json

仅当需要通过定义更新显示名称或描述而必须包含`.platform`文件时,才使用`?updateMetadata=true`查询参数。

---

Authoring Scope Matrix

创作范围矩阵

OperationSupportedMethod
Create semantic model with TMDL
POST /v1/workspaces/{id}/semanticModels
with definition
Get/download TMDL definition
POST .../semanticModels/{id}/getDefinition?format=TMDL
Update full TMDL definition
POST .../semanticModels/{id}/updateDefinition
Delete semantic model
DELETE /v1/workspaces/{id}/semanticModels/{id}
Refresh datasetPower BI Datasets API (Phase 4)
Add/modify single measure or column⚠️ Route to
powerbi-modeling-mcp
Full definition round-trip is inefficient
Create reportsNot in scope — separate definition format (PBIR)

操作是否支持方法
使用TMDL创建语义模型
POST /v1/workspaces/{id}/semanticModels
并附带定义
获取/下载TMDL定义
POST .../semanticModels/{id}/getDefinition?format=TMDL
更新完整TMDL定义
POST .../semanticModels/{id}/updateDefinition
删除语义模型
DELETE /v1/workspaces/{id}/semanticModels/{id}
刷新数据集Power BI Datasets API(第4阶段)
添加/修改单个度量值或列⚠️ 路由至
powerbi-modeling-mcp
完整定义往返效率低下
创建报表不在本技能范围内 — 需要单独的定义格式(PBIR)

Refresh Operations

刷新操作

All refresh operations use the Power BI Datasets API audience (
https://analysis.windows.net/powerbi/api
).
bash
WS_ID="<workspaceId>"
DATASET_ID="<semanticModelId>"
PBI="https://api.powerbi.com/v1.0/myorg"
所有刷新操作均使用Power BI Datasets API受众(
https://analysis.windows.net/powerbi/api
)。
bash
WS_ID="<workspaceId>"
DATASET_ID="<semanticModelId>"
PBI="https://api.powerbi.com/v1.0/myorg"

Trigger full refresh

触发完整刷新

cat > /tmp/body.json << 'EOF' {"notifyOption": "NoNotification"} EOF az rest --method post --verbose
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes"
--headers "Content-Type=application/json"
--body @/tmp/body.json
cat > /tmp/body.json << 'EOF' {"notifyOption": "NoNotification"} EOF az rest --method post --verbose
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes"
--headers "Content-Type=application/json"
--body @/tmp/body.json

Get refresh history (latest first)

获取刷新历史(最新的在前)

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes?$top=5"
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes?$top=5"

Cancel an in-progress refresh

取消正在进行的刷新

az rest --method delete
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes/<refreshId>"
az rest --method delete
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes/<refreshId>"

Get refresh schedule

获取刷新调度

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshSchedule"
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshSchedule"

Update refresh schedule

更新刷新调度

cat > /tmp/body.json << 'EOF' { "value": { "enabled": true, "days": ["Monday", "Wednesday", "Friday"], "times": ["02:00", "14:00"], "localTimeZoneId": "UTC" } } EOF az rest --method patch
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshSchedule"
--headers "Content-Type=application/json"
--body @/tmp/body.json

---
cat > /tmp/body.json << 'EOF' { "value": { "enabled": true, "days": ["Monday", "Wednesday", "Friday"], "times": ["02:00", "14:00"], "localTimeZoneId": "UTC" } } EOF az rest --method patch
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshSchedule"
--headers "Content-Type=application/json"
--body @/tmp/body.json

---

Data Sources & Parameters

数据源与参数

bash
undefined
bash
undefined

Get data sources for a dataset

获取数据集的数据源

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/datasources"
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/datasources"

Get parameters

获取参数

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/parameters"
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/parameters"

Update parameters

更新参数

cat > /tmp/body.json << 'EOF' { "updateDetails": [ {"name": "Server", "newValue": "newserver.database.windows.net"}, {"name": "Database", "newValue": "ProductionDB"} ] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/Default.UpdateParameters"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> After updating parameters or data source credentials, trigger a refresh for changes to take effect.

---
cat > /tmp/body.json << 'EOF' { "updateDetails": [ {"name": "Server", "newValue": "newserver.database.windows.net"}, {"name": "Database", "newValue": "ProductionDB"} ] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/Default.UpdateParameters"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> 更新参数或数据源凭据后,请触发刷新以使更改生效。

---

Permissions

权限

bash
undefined
bash
undefined

List dataset users

列出数据集用户

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"

Grant dataset permissions to a user

为用户授予数据集权限

cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read" } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json
cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read" } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

Update existing user permissions

更新现有用户权限

cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "ReadReshare" } EOF az rest --method put
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

Permission levels: `Read`, `ReadReshare`, `ReadExplore`, `ReadReshareExplore`.

---
cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "ReadReshare" } EOF az rest --method put
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

权限级别:`Read`、`ReadReshare`、`ReadExplore`、`ReadReshareExplore`。

---

Security Role Memberships

安全角色成员

After defining RLS/OLS roles in TMDL (see Security Roles), use the Power BI Datasets API to assign users and groups to those roles.
bash
PBI="https://api.powerbi.com/v1.0/myorg"
在TMDL中定义RLS/OLS角色后(请参阅安全角色),使用Power BI Datasets API为这些角色分配用户和组。
bash
PBI="https://api.powerbi.com/v1.0/myorg"

List members of a security role

列出安全角色的成员

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
| jq '[.value[] | select(.datasetUserAccessRight == "Read" and .roles != null)]'
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
| jq '[.value[] | select(.datasetUserAccessRight == "Read" and .roles != null)]'

Add a user to a security role

将用户添加到安全角色

cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read", "roles": ["SalesRegion"] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json
cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read", "roles": ["SalesRegion"] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

Add a security group to a role

将安全组添加到角色

cat > /tmp/body.json << 'EOF' { "identifier": "<group-object-id>", "principalType": "Group", "datasetUserAccessRight": "Read", "roles": ["SalesRegion"] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json
cat > /tmp/body.json << 'EOF' { "identifier": "<group-object-id>", "principalType": "Group", "datasetUserAccessRight": "Read", "roles": ["SalesRegion"] } EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

Update role membership (e.g., move user to a different role)

更新角色成员(例如,将用户移动到其他角色)

cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read", "roles": ["EuropeOnly"] } EOF az rest --method put
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> The `roles` array accepts one or more role names that must match roles defined in the semantic model's TMDL. The user/group must also have at least `Read` permission on the dataset. `principalType` can be `User`, `Group`, or `App`.

---
cat > /tmp/body.json << 'EOF' { "identifier": "user@contoso.com", "principalType": "User", "datasetUserAccessRight": "Read", "roles": ["EuropeOnly"] } EOF az rest --method put
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/users"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> `roles`数组接受一个或多个角色名称,必须与语义模型TMDL中定义的角色匹配。用户/组还必须至少拥有数据集的`Read`权限。`principalType`可以是`User`、`Group`或`App`。

---

Deployment Pipelines

部署流水线

Deployment pipelines use the Fabric API audience (
https://api.fabric.microsoft.com
).
bash
FABRIC="https://api.fabric.microsoft.com/v1"
部署流水线使用Fabric API受众(
https://api.fabric.microsoft.com
)。
bash
FABRIC="https://api.fabric.microsoft.com/v1"

List deployment pipelines

列出部署流水线

az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines"
az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines"

Get pipeline stages

获取流水线阶段

az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/<pipelineId>/stages"
az rest --method get
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/<pipelineId>/stages"

Deploy from one stage to the next (e.g., Dev → Test)

从一个阶段部署到下一个阶段(例如,从开发到测试)

cat > /tmp/body.json << 'EOF' { "sourceStageOrder": 0, "targetStageOrder": 1, "items": [ { "sourceItemId": "<semanticModelId>", "itemType": "SemanticModel" } ], "options": { "allowCreateArtifact": true, "allowOverwriteArtifact": true } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/<pipelineId>/deploy"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> Omit the `items` array to deploy all items in the stage. The deploy call returns `202 Accepted` — poll using the [LRO pattern](../../common/COMMON-CLI.md#long-running-operations-lro-pattern).

---
cat > /tmp/body.json << 'EOF' { "sourceStageOrder": 0, "targetStageOrder": 1, "items": [ { "sourceItemId": "<semanticModelId>", "itemType": "SemanticModel" } ], "options": { "allowCreateArtifact": true, "allowOverwriteArtifact": true } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/<pipelineId>/deploy"
--headers "Content-Type=application/json"
--body @/tmp/body.json

> 省略`items`数组将部署阶段中的所有项。部署调用会返回`202 Accepted` — 请按照[LRO模式](../../common/COMMON-CLI.md#long-running-operations-lro-pattern)进行轮询。

---

Agentic Workflow

智能工作流

Tool Selection Priority

工具选择优先级

  1. powerbi-modeling-mcp
    available
    → use MCP tools for fine-grained object changes (measures, columns, relationships)
  2. MCP unavailable, TMDL files available → edit TMDL files directly, deploy via
    az rest
    updateDefinition
  3. MCP unavailable, workspace only → use this skill: getDefinition → edit TMDL → updateDefinition
  1. powerbi-modeling-mcp
    可用
    → 使用MCP工具进行细粒度对象更改(度量值、列、关系)
  2. MCP不可用,但有TMDL文件 → 直接编辑TMDL文件,通过
    az rest
    的updateDefinition部署
  3. MCP不可用,仅能访问工作区 → 使用本技能:getDefinition → 编辑TMDL → updateDefinition

Workflow Steps

工作流步骤

  1. Discover workspace → list workspaces, find target by name (see COMMON-CLI.md § Finding Workspaces and Items)
  2. List semantic models
    GET /v1/workspaces/{id}/semanticModels
    to find existing models or confirm name availability
  3. Analyze source schema → inspect source tables/columns via SQL, DAX, or Lakehouse metadata to inform star schema design
  4. Design star schema → identify fact and dimension tables, define relationship keys, plan measures
  5. Author TMDL files → create
    definition.pbism
    ,
    database.tmdl
    ,
    model.tmdl
    , and table files per Minimal TMDL Content Examples and tmdl-authoring-guide.md
  6. Create relationships → define in table TMDL files before creating measures that depend on them
  7. Create measures → add explicit measures with
    formatString
    for all aggregatable values
  8. Deploy → base64-encode all parts → POST createItemWithDefinition (see Create Semantic Model)
  9. Verify → run validation checks (see below)
  10. Refresh → trigger dataset refresh via Refresh Operations
  11. Validate with DAX → use powerbi-consumption-cli to run DAX queries against the deployed model
  1. 发现工作区 → 列出工作区,按名称找到目标工作区(请参阅COMMON-CLI.md § 查找工作区和项
  2. 列出语义模型 → 调用
    GET /v1/workspaces/{id}/semanticModels
    查找现有模型或确认名称可用
  3. 分析源架构 → 通过SQL、DAX或湖仓元数据检查源表/列,为星型架构设计提供依据
  4. 设计星型架构 → 识别事实表和维度表,定义关系键,规划度量值
  5. 创作TMDL文件 → 根据最小TMDL内容示例tmdl-authoring-guide.md创建
    definition.pbism
    database.tmdl
    model.tmdl
    和表文件
  6. 创建关系 → 在依赖关系的度量值创建前,在表TMDL文件中定义关系
  7. 创建度量值 → 为所有可聚合值添加带
    formatString
    的显式度量值
  8. 部署 → 对所有部分进行Base64编码 → POST调用createItemWithDefinition(请参阅创建语义模型
  9. 验证 → 运行验证检查(如下所示)
  10. 刷新 → 通过刷新操作触发数据集刷新
  11. 使用DAX验证 → 使用powerbi-consumption-cli对已部署模型运行DAX查询

Post-Creation Validation

创建后验证

  • TMDL structure — verify all required parts are present (definition.pbism, database.tmdl, model.tmdl, ≥1 table)
  • Test measures — run
    EVALUATE { [Measure Name] }
    for each measure via DAX
  • Verify relationships — confirm cardinality, cross-filter direction, matching
    dataType
    on both sides
  • Verify columns — confirm
    sourceColumn
    mappings and
    dataType
    match source schema
  • Check for duplicates — no duplicate measure names or orphan objects

  • TMDL结构 — 验证所有必填部分是否存在(definition.pbism、database.tmdl、model.tmdl、至少1个表)
  • 测试度量值 — 通过DAX运行
    EVALUATE { [度量值名称] }
    来测试每个度量值
  • 验证关系 — 确认基数、交叉筛选方向、两侧
    dataType
    匹配
  • 验证列 — 确认
    sourceColumn
    映射和
    dataType
    与源架构匹配
  • 检查重复项 — 没有重复的度量值名称或孤立对象

Troubleshooting

故障排除

Early-abort rule: If both
getDefinition
returns
404 EntityNotFound
(on an item you can list/GET) and the Power BI refresh API returns
403 Forbidden
with
"identity None"
, stop retrying immediately — the user almost certainly has only Viewer role on the workspace. Verify by calling
GET /v1/workspaces/{id}/roleAssignments
; if that also returns
403 InsufficientWorkspaceRole
, confirm to the user they need Contributor or higher role. Do not retry with different URL formats, endpoints, or parameters — the issue is permissions, not API usage.
SymptomCauseFix
403 Forbidden
with
"identity None"
on Power BI API
User has Viewer role — refresh, data sources, and permissions APIs require Contributor+Stop immediately. Ask user to request Contributor/Member/Admin role on the workspace
404 EntityNotFound
on getDefinition but item exists in list
Insufficient permissions masquerading as 404 — getDefinition requires Contributor+Check workspace role first; do not retry with different URL formats
403 InsufficientWorkspaceRole
on roleAssignments
User is Viewer on the workspaceConfirms Viewer role — all authoring and most read operations are blocked
401 Unauthorized
on Fabric API
Wrong or missing
--resource
Use
--resource "https://api.fabric.microsoft.com"
401 Unauthorized
on Power BI API
Wrong audienceUse
--resource "https://analysis.windows.net/powerbi/api"
411 Length Required
on getDefinition
Missing request bodyPass
--body '{}'
— getDefinition is a POST
LRO poll never completesToken expired during long operationRe-acquire token in poll loop; increase Retry-After interval
202 Accepted
but no result
Didn't follow LRO to completionPoll
Location
header URL until
Succeeded
, then GET
/result
TMDL validation error on create/updateSyntax error in TMDL contentCheck TMDL rules in tmdl-authoring-guide.md; validate before encoding
Parts missing after updateDefinitionOnly modified parts were sentMust include ALL parts (modified + unmodified) in every update
Error including
.platform
in update
.platform
not accepted by default
Remove
.platform
from parts, or use
?updateMetadata=true
Base64 decode produces garbled contentWrong encoding or line wrappingUse
base64 -w 0
(no line wrap) or
[Convert]::ToBase64String()
Refresh fails with data source errorCredentials expired or parameters wrongCheck data sources and parameters; update credentials if needed
Deployment pipeline failsWorkspace not assigned to stageAssign workspace to pipeline stage before deploying
lineageTag
conflict on new objects
Manually added
lineageTag
Remove
lineageTag
from new objects — it is auto-generated
DAX error testing measuresMeasure name case mismatchDAX measure names are case-sensitive; match exactly
Attempting
INFO.ROLES()
/
INFO.ROLEMEMBERSHIPS()
via DAX to retrieve role members
DAX
INFO
functions do not reliably return role membership data and may return empty or incomplete results
Use the Power BI REST API instead:
GET /v1.0/myorg/groups/{workspaceId}/datasets/{datasetId}/users
and filter by
roles
field (see Security Role Memberships)

提前终止规则:如果同时出现
getDefinition
返回
404 EntityNotFound
(针对你能列出/GET的项)Power BI刷新API返回
403 Forbidden
并附带
"identity None"
请立即停止重试 — 用户几乎可以肯定仅拥有工作区的查看者角色。通过调用
GET /v1/workspaces/{id}/roleAssignments
验证;如果该调用也返回
403 InsufficientWorkspaceRole
,请向用户确认他们需要贡献者或更高角色。不要尝试不同的URL格式、端点或参数 — 问题出在权限,而非API使用方式。
症状原因修复方案
Power BI API返回
403 Forbidden
并附带
"identity None"
用户拥有查看者角色 — 刷新、数据源和权限API需要贡献者及以上角色立即停止操作。请用户申请工作区的贡献者/成员/管理员角色
getDefinition返回
404 EntityNotFound
但项在列表中存在
权限不足伪装成404错误 — getDefinition需要贡献者及以上角色先检查工作区角色;不要尝试不同的URL格式
roleAssignments返回
403 InsufficientWorkspaceRole
用户是工作区的查看者确认查看者角色 — 所有创作和大多数读取操作均被阻止
Fabric API返回
401 Unauthorized
--resource
参数错误或缺失
使用
--resource "https://api.fabric.microsoft.com"
Power BI API返回
401 Unauthorized
受众错误使用
--resource "https://analysis.windows.net/powerbi/api"
getDefinition返回
411 Length Required
缺少请求体传递
--body '{}'
— getDefinition是POST请求
LRO轮询永远无法完成长时间操作期间令牌过期在轮询循环中重新获取令牌;增加Retry-After间隔
返回
202 Accepted
但无结果
未完成LRO轮询轮询
Location
响应头中的URL直至状态为
Succeeded
,然后GET
/result
创建/更新时出现TMDL验证错误TMDL内容存在语法错误检查tmdl-authoring-guide.md中的TMDL规则;编码前先验证
updateDefinition后部分内容缺失仅发送了修改的部分每次更新必须包含所有部分(修改的+未修改的)
更新中包含
.platform
时出错
默认不接受
.platform
从部分中移除
.platform
,或使用
?updateMetadata=true
Base64解码产生乱码编码错误或换行使用
base64 -w 0
(无换行)或
[Convert]::ToBase64String()
刷新因数据源错误失败凭据过期或参数错误检查数据源和参数;必要时更新凭据
部署流水线失败工作区未分配到阶段部署前将工作区分配到流水线阶段
新对象出现
lineageTag
冲突
手动添加了
lineageTag
从新对象中移除
lineageTag
— 它会自动生成
测试度量值时出现DAX错误度量值名称大小写不匹配DAX度量值名称区分大小写;需完全匹配
尝试通过DAX的
INFO.ROLES()
/
INFO.ROLEMEMBERSHIPS()
检索角色成员
DAX
INFO
函数无法可靠返回角色成员数据,可能返回空或不完整结果
请改用Power BI REST API
GET /v1.0/myorg/groups/{workspaceId}/datasets/{datasetId}/users
并按
roles
字段筛选(请参阅安全角色成员

Examples

示例

Create a Semantic Model from TMDL

从TMDL创建语义模型

bash
WS_ID="<workspaceId>"
bash
WS_ID="<workspaceId>"

Encode all TMDL files

编码所有TMDL文件

PBISM=$(base64 -w 0 < definition.pbism) DB=$(base64 -w 0 < definition/database.tmdl) MODEL=$(base64 -w 0 < definition/model.tmdl) CUSTOMER=$(base64 -w 0 < definition/tables/Customer.tmdl) SALES=$(base64 -w 0 < definition/tables/Sales.tmdl)
cat > /tmp/body.json << EOF { "displayName": "SalesModel", "definition": { "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$CUSTOMER", "payloadType": "InlineBase64"}, {"path": "definition/tables/Sales.tmdl", "payload": "$SALES", "payloadType": "InlineBase64"} ] } } EOF az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels"
--headers "Content-Type=application/json"
--body @/tmp/body.json
undefined
PBISM=$(base64 -w 0 < definition.pbism) DB=$(base64 -w 0 < definition/database.tmdl) MODEL=$(base64 -w 0 < definition/model.tmdl) CUSTOMER=$(base64 -w 0 < definition/tables/Customer.tmdl) SALES=$(base64 -w 0 < definition/tables/Sales.tmdl)
cat > /tmp/body.json << EOF { "displayName": "SalesModel", "definition": { "parts": [ {"path": "definition.pbism", "payload": "$PBISM", "payloadType": "InlineBase64"}, {"path": "definition/database.tmdl", "payload": "$DB", "payloadType": "InlineBase64"}, {"path": "definition/model.tmdl", "payload": "$MODEL", "payloadType": "InlineBase64"}, {"path": "definition/tables/Customer.tmdl", "payload": "$CUSTOMER", "payloadType": "InlineBase64"}, {"path": "definition/tables/Sales.tmdl", "payload": "$SALES", "payloadType": "InlineBase64"} ] } } EOF az rest --method post --verbose
--resource "https://api.fabric.microsoft.com"
--url "https://api.fabric.microsoft.com/v1/workspaces/$WS_ID/semanticModels"
--headers "Content-Type=application/json"
--body @/tmp/body.json
undefined

Download a Semantic Model Definition

下载语义模型定义

bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"
bash
WS_ID="<workspaceId>"
MODEL_ID="<semanticModelId>"

Get definition (may return 202 — follow LRO)

获取定义(可能返回202 — 请遵循LRO流程)

Decode and save all parts

解码并保存所有部分

echo "$RESULT" | jq -r '.definition.parts[] | .path + "\t" + .payload' |
while IFS=$'\t' read -r path payload; do mkdir -p "$(dirname "$path")" echo "$payload" | base64 -d > "$path" echo "Saved: $path" done
undefined
echo "$RESULT" | jq -r '.definition.parts[] | .path + "\t" + .payload' |
while IFS=$'\t' read -r path payload; do mkdir -p "$(dirname "$path")" echo "$payload" | base64 -d > "$path" echo "已保存:$path" done
undefined

Trigger a Refresh and Check Status

触发刷新并检查状态

bash
WS_ID="<workspaceId>"
DATASET_ID="<semanticModelId>"
PBI="https://api.powerbi.com/v1.0/myorg"
bash
WS_ID="<workspaceId>"
DATASET_ID="<semanticModelId>"
PBI="https://api.powerbi.com/v1.0/myorg"

Trigger refresh

触发刷新

cat > /tmp/body.json << 'EOF' {"type": "Full"} EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes"
--body @/tmp/body.json
cat > /tmp/body.json << 'EOF' {"type": "Full"} EOF az rest --method post
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes"
--body @/tmp/body.json

Check latest refresh status

检查最新刷新状态

az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes?$top=1"
undefined
az rest --method get
--resource "https://analysis.windows.net/powerbi/api"
--url "$PBI/groups/$WS_ID/datasets/$DATASET_ID/refreshes?$top=1"
undefined

Deploy to Production via Pipeline

通过流水线部署到生产环境

bash
FABRIC="https://api.fabric.microsoft.com/v1"
PIPELINE_ID="<pipelineId>"
bash
FABRIC="https://api.fabric.microsoft.com/v1"
PIPELINE_ID="<pipelineId>"

Deploy from Test (stage 1) to Production (stage 2)

从测试阶段(阶段1)部署到生产阶段(阶段2)

cat > /tmp/body.json << 'EOF' { "sourceStageOrder": 1, "targetStageOrder": 2, "items": [ {"sourceItemId": "<semanticModelId>", "itemType": "SemanticModel"} ], "options": { "allowCreateArtifact": true, "allowOverwriteArtifact": true } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/$PIPELINE_ID/deploy"
--body @/tmp/body.json
undefined
cat > /tmp/body.json << 'EOF' { "sourceStageOrder": 1, "targetStageOrder": 2, "items": [ {"sourceItemId": "<semanticModelId>", "itemType": "SemanticModel"} ], "options": { "allowCreateArtifact": true, "allowOverwriteArtifact": true } } EOF az rest --method post
--resource "https://api.fabric.microsoft.com"
--url "$FABRIC/deploymentPipelines/$PIPELINE_ID/deploy"
--body @/tmp/body.json
undefined