Power BI 中的作者模板内容包Author template content packs in Power BI

在创作模板内容包时需使用 Power BI Desktop 和 PowerBI.com。内容包具有四个组件︰Authoring a template content pack uses the Power BI Desktop and PowerBI.com. There are four components to your content pack:

你可能熟悉其中每个部分(作为现有 Power BI 功能)。You may be familiar with each piece as existing Power BI features. 在生成内容包时,还需考虑其中每个方面的其他一些事项。请参阅下一节了解有关详细信息。When building a content pack, there are additional things to consider for each aspect, see each section below for more details.

查询Queries

对于模板内容包,在 Power BI Desktop 中开发的查询用于连接数据源和导入数据。For template content packs, queries developed in the Power BI Desktop are used to connect to your data source and import data. 必须使用这些查询返回一致的架构,并且它们受支持以用于计划的数据刷新(不支持直接查询)。These queries are required to return a consistent schema and are supported for Scheduled Data refresh (direct query is not supported).

对于每个内容包,模板内容包仅支持一个数据源,因此请认真定义你的查询。Template content packs only support one data source per content pack so define your queries carefully. 将单个数据源定义为需要相同的身份验证的源。A single data source is defined as a source that requires the same authentication. 如果所有调用针对的是相同的 API 终结点且使用相同的身份验证,则可以在不同的查询中进行多次 API 调用。You can make multiple API calls in different queries if all the calls are to the same API endpoint and use the same authentication. Power BI 内容包不支持需要不同身份验证的多个源。Power BI content packs do not support multiple sources that require different authentications.

连接到 APIConnect to your API

需要从 Power BI Desktop 连接到你的 API 才能开始生成查询。To get started, you will need to connect to your API from Power BI Desktop to start building your queries.

可以使用 Power BI Desktop 中现成可用的数据连接器连接到 API。You can use the Data Connectors that are available out of the box in Power BI Desktop to connect to your API. 可以使用 Web 数据连接器(获取数据 -> Web)连接到 Rest API 或 OData 连接器(获取数据 -> OData 数据源)来连接到 OData 数据源。You can use the Web Data Connector (Get Data -> Web) to connect to your Rest API or the OData connector (Get Data -> OData feed) to connect to your OData feed. 请注意,这些连接器只有在你的 API 支持基本身份验证时才是现成可用的。Please note that these connectors will work out of the box only if your API supports Basic Authentication.

备注

如果你的 API 使用任何其他身份验证类型,如 OAuth 2.0 或 Web API 密钥,则需要开发你自己的数据连接器,以允许 Power BI Desktop 成功连接到 API,并对其进行身份验证。If your API uses any other authentication types, like OAuth 2.0 or Web API Key, then you will need to develop your own Data Connector to allow Power BI Desktop to successfully connects and authenticates to your API. 有关如何为内容包开发你自己的数据连接器的详细信息,请查看此处的数据连接器文档。For details on how to develop your own Data Connector for your Content Pack, check the Data Connectors documentation here.

考虑源Consider the source

查询可定义将包含在数据模型中的数据。The queries define the data that will be included in the data model. 根据你系统的大小,这些查询还应包括筛选器以确保客户处理适合你业务方案的可管理的查询量。Depending on the size of your system, these queries should also include filters to ensure your customers are dealing with a manageable size that fits your business scenario.

Power BI 内容包可并行执行多个查询,也可同时为多个用户执行查询。Power BI content packs can execute multiple queries in parallel and for multiple users concurrently. 请提前规划你的限制条件和并发策略,并就如何使你的内容包具备容错能力向我们需求帮助。Plan ahead your throttling and concurrency strategy and ask us how to make your content pack fault tolerant.

架构实施Schema enforcement

确保你的查询能够弹性应对系统中发生的更改,刷新时的架构变更可破坏模型。Ensure your queries are resilient to changes in your system, changes in schema on refresh can break the model. 如果源可能为某些查询返回 null/架构缺失结果,请考虑返回一个空表,或者引发一条对你的用户有意义的自定义错误消息。If the source could return null/missing schema result for some queries, consider returning an empty table or throw a custom error messages that is meaningful to your user.

参数Parameters

Power BI Desktop 中的参数允许你的用户提供用于自定义数据(由用户检索)的输入值。Parameters in Power BI Desktop allow your users to provide input values that customize the data retrieved by the user. 提前考虑这些参数以避免在耗费时间生成详细的查询或报表之后返工。Think of the parameters upfront to avoid rework after investing time to build detailed queries or reports.

备注

模板内容包目前仅支持文本参数。Template content packs only support text parameters currently. 在开发过程中可以使用其他参数类型,但在测试部分中中用户所提供的所有值将为文字内容。Other parameter types can be used during development but during the testing portion all values provided by the users will be literal.

其他查询提示Additional query tips

  • 确保正确键入所有列Ensure all columns are typed appropriately
  • 列具有描述性名称(请参阅问题解答)Columns have informative names (see Q&A)
  • 对于共享逻辑,请考虑使用函数或查询For shared logic, consider using functions or queries
  • 隐私级别目前在服务中不受支持 - 如果显示有关隐私级别的提示,你可能需要重新编写查询以使用相对路径Privacy levels are not currently supported in the service - if you get a prompt about privacy levels, you may need to re-write the query to use relative paths

数据模型Data Model

已进行完善定义的数据模型将确保你的客户可轻松直观地与内容包交互。A well-defined data model will ensure your customers can easily and intuitively interact with the content pack. 在 Power BI Desktop 中创建数据模型。Create the data model in the Power BI Desktop.

备注

大部分基本建模(键入功能、列名)应在查询中完成。Much of the basic modelling (typing, column names) should be done in the queries.

问题解答Q&A

建模还将影响问题解答为客户提供结果的能力。The modelling will also affect how well Q&A can provide results for your customers. 确保将同义词添加到常用列,并在查询中为你的列正确命名。Ensure you add synonyms to commonly used columns and that your columns are properly named in the queries.

其他数据模型提示Additional data model tips

  • 所有值列已应用格式设置All value columns have formatting applied >[!NOTE] >应在查询中应用类型。Types should be applied in the query.
  • 所有度量值已应用格式All measures have formatting applied
  • 已设置“默认摘要”。Default Summarization is set. 特别是“不汇总”(如果适用)(例如,对于唯一值的情况)Especially "Do Not Summarize", when applicable (for unique values for example)
  • 已设置数据类别(如果适用)Data Category has been set, when applicable
  • 已设置关系(根据需要)Relationships are set, as necessary

报表Reports

报表页提供了更多关于你内容包中数据的见解。The report pages offer additional insight into the data included in your content pack. 使用报表中的页面来回答你的内容包正尝试解决的关键业务问题。Use the pages of the reports to answer the key business questions your content pack is trying to address. 使用 Power BI Desktop 创建报表。Create the report using the Power BI Desktop.

备注

内容包中只能包含一个报表,可以利用不同页面调出你方案的特定部分。Only one report may be included in a content pack, take advantage of the different pages to call out particular sections of your scenario.

其他报表提示Additional report tips

  • 对每个页面使用多个视觉对象以进行交叉筛选Use more than one visual per page for cross-filtering
  • 仔细使各视觉对象对齐(不重叠)Align the visuals carefully (no overlapping)
  • 页面设置为“4:3”或“16:9”布局模式Page is set to "4:3" or "16:9" mode for layout
  • 所提供的全部聚合将使数字有意义(平均值、唯一值)All of the aggregations presented make numeric sense (averages, unique values)
  • 切片产生合理结果Slicing produces rational results
  • 徽标至少位于报表顶部Logo is present on at least the top report
  • 元素最尽可能地位于客户端的的配色方案中Elements are in the client's color scheme to the extent possible

仪表板Dashboard

仪表板是与你客户的内容包交互的主要位置。The dashboard is the main point of interaction with your content pack for your customers. 它应包括所含内容(尤其是你业务方案的重要指标)的概述。It should include an overview of the content included, especially the important metrics for your business scenario.

要为模板内容包创建仪表板,只需通过“获取数据”>“文件”上载你的 PBIX 或者直接从 Power BI Desktop 进行发布即可。To create a dashboard for your template content pack, simply upload your PBIX through Get Data > Files or publish directly from the Power BI Desktop.

备注

模板内容包目前需要对每个内容包使用单个报表和数据集。Template content packs currently require a single report and dataset per content pack. 不要将多个报表/数据集的内容固定到内容包所使用的仪表板中。Do not pin content from multiple reports/datasets onto the dashboard used in the content pack.

其他仪表板提示Additional dashboard tips

  • 在固定时保持相同的主题,以便你仪表板上的磁贴保持一致Maintain the same theme when pinning so that the tiles on your dashboard are consistent
  • 将徽标固定到主题,以便使用者知道包的来源Pin a logo to the theme so consumers know where the pack is from
  • 建议用于多数屏幕分辨率的布局是 5-6 个小磁贴的宽度Suggested layout to work with most screen resolutions is 5-6 small tiles wide
  • 所有仪表板磁贴应具有适当的标题/副标题All dashboard tiles should have appropriate titles/subtitles
  • 考虑在仪表板中为不同的方案分组(垂直或水平)Consider groupings in the dashboard for different scenarios, either vertically or horizontally

限制条件摘要Summary of restrictions

如前面几节中所列,模板内容包目前存在一组限制 ︰As listed in the above sections, currently the template content packs have a set of restrictions:

受支持Supported 不支持Not Supported
在 PBI 桌面中生成的数据集Datasets built in PBI Desktop 来自其他内容包或输入(如 Excel 文件)的数据集Datasets from other content packs or inputs such as Excel files
可支持云“计划数据”刷新的数据源Data source supported for cloud Scheduled Data refresh 不支持直接查询或本地连接Direct query or on-prem connecitivty is not supported
将返回一致的架构或错误的查询(在适当时)Queries returning consistent schema or errors where appropriate 动态架构或自定义架构Dynamic or custom schemas
每个数据集一个数据源One data source per dataset 多个数据源(例如被检测为多个数据源的混合 Web 应用程序或 URL)Multiple data sources such as mashups or URLs that are detected as mutliple data sources
文本类型的参数Parameters of type text 其他参数类型(例如日期)或者“列出允许的值”Other parameter types (such as date) or "list allowed of values"
一个仪表板、报表和数据集One dashboard, report and dataset 多个仪表板、报表或数据集Multiple dashboards, reports or datasets

下一步Next step

内容包测试和提交Content Pack Testing and Submission