Power BI 工作区集合入门Get started with Power BI Workspace Collections

Power BI 工作区集合是一项 Azure 服务,应用程序开发人员可通过它将交互式 Power BI 报表添加到自己的应用程序中。Power BI Workspace Collections are an Azure service that enables application developers to add interactive Power BI reports into their own applications. Power BI 工作区集合可配合现有应用程序使用,无需重新设计或更改用户登录方式。Power BI Workspace Collections work with existing applications without needing redesign or changing the way users sign in.

重要

Power BI 工作区集合已弃用,到 2018 年 6 月 或合同指示时可用。Power BI Workspace Collections is deprecated and is available until June 2018 or when your contract indicates. 建议你规划到 Power BI Embedded 的迁移以避免应用程序中断。You are encouraged to plan your migration to Power BI Embedded to avoid interruption in your application. 有关如何将数据迁移到 Power BI Embedded 的信息,请参阅如何将 Power BI 工作区集合内容迁移到 Power BI EmbeddedFor information on how to migrate your data to Power BI Embedded, see How to migrate Power BI Workspace Collections content to Power BI Embedded.

Power BI 工作区集合的资源通过 Azure 资源管理器 API 进行预配。Resources for Power BI Workspace Collections are provisioned through the Azure Resource Manager APIs. 在这种情况下,预配的资源为 Power BI 工作区集合In this case, the resource provisioned is a Power BI Workspace Collection.

Power BI 工作区集合的常规流

创建工作区集合Create a workspace collection

工作区集合 是顶层的 Azure 资源,是要嵌入到应用程序中的内容的容器。A Workspace Collection is the top-level Azure resource and a container for the content that will be embedded in your application. 可采用两种方式创建工作区集合:A Workspace Collection can be created in two ways:

  • 使用 Azure 门户手动创建Manually using the Azure portal
  • 使用 Azure 资源管理器 API 以编程方式创建Programmatically using the Azure Resource Manager APIs

以下让我们逐步完成使用 Azure 门户构建工作区集合的步骤。Let's walk through the steps to build a Workspace Collection using the Azure portal.

  1. 打开 Azure 门户 (https://portal.azure.cn) 并登录到其中。Open and sign into Azure portal: https://portal.azure.cn.

  2. 在顶部面板上选择“+ 新建”。Select + New on the top panel.

    Azure 门户中的“+ 新建”

  3. 在“数据 + 分析”下选择“Power BI 工作区集合”。Under Data + Analytics, select Power BI Workspace Collection.

  4. 如果已经有了 Power BI 工作区集合订阅,则请在入门消息底部选择“创建工作区集合”。Within the get started message, if you already have an existing Power BI Workspace Collection subscription, select Create a workspace collection at the bottom.

  5. 在“工作区集合”上输入所需的信息。On Workspace Collection, enter the required information.

    创建工作区集合

  6. 选择“创建” 。Select Create.

工作区集合需要一些时间进行预配。The Workspace Collection takes a few moments to provision. 完成后会转到“工作区集合”。When completed, you are taken to Workspace Collection.

Azure 门户中的工作区集合

“创建”结果包含调用创建工作区并向其部署内容的 API 所需的信息。The Creation results contain the information you need to call the APIs that create workspaces and deploy content to them.

查看 Power BI API 访问密钥View Power BI API access keys

调用 Power BI REST API 所需的最重要信息之一是 访问密钥One of the most important pieces of information needed to call the Power BI REST APIs are the Access Keys. 这些访问密钥用于生成对 API 请求进行身份验证的 应用程序令牌These are used to generate the app tokens that are used to authenticate your API requests. 若要查看访问密钥,请单击“设置”上的“访问密钥”。To view your Access Keys, click Access Keys on Settings. 有关应用令牌的详细信息,请参阅通过 Power BI 工作区集合进行身份验证和授权For more about app tokens, see Authenticating and authorizing with Power BI Workspace Collections.

Azure 门户的“工作区集合”设置中的访问密钥

你会发现有两个密钥。You'll notice that you have two keys.

访问密钥中的两个密钥

复制这两个密钥并将它们安全存储在应用程序中。Copy these keys and store them securely in your application. 重要的是,要像对待密码一样对待这些密钥,因为它们可以提供工作区集合中所有内容的访问权限。It's important that you treat these keys as you would a password, because they provide access to all the content in your Workspace Collection.

虽然列出了两个密钥,但是一次只需要一个密钥。While two keys are listed, only one key is needed at a particular time. 提供第二个密钥以便定期重新生成密钥,且无需中断对服务的访问。The second key is provided so you can periodically regenerate keys without interrupting access to the service.

现在,应用程序具有一个 Power BI 实例和访问密钥,可以将报表导入自己的应用程序中。Now that you have an instance of Power BI for your application, and Access Keys, you can import a report into your own app. 在了解如何导入报表之前,下一节介绍了如何创建要嵌入到应用程序中的 Power BI 数据集和报表。Before you learn how to import a report, the next section describes creating Power BI datasets and reports to embed into an app.

使用工作区Working with workspaces

创建工作区集合后,需要创建一个用于容装报表和数据集的工作区。After you have created your workspace collection, you will need to create a workspace that will house your reports and datasets. 若要创建工作区,需使用 POST 工作区 REST APITo create a workspace, you need to use the Post Workspace REST API.

使用 Power BI Desktop 创建要嵌入到应用程序中的 Power BI 数据集和报表Create Power BI datasets and reports to embed into an app using Power BI Desktop

至此,已创建应用程序的 Power BI 实例,并有了访问密钥,接下来需要创建要嵌入的 Power BI 数据集和报表。Now that you have created an instance of Power BI for your application, and have Access Keys, you need to create the Power BI datasets and reports that you want to embed. 可以使用 Power BI Desktop创建数据集和报表。Datasets and reports can be created by using Power BI Desktop. 可以下载 Power BI Desktop进行免费试用。You can download Power BI Desktop for free. 或者,若要快速开始使用,可以下载 零售分析示例 PBIXOr, to quickly get started, you can download the Retail Analysis Sample PBIX.

备注

若要了解有关如何使用 Power BI Desktop的详细信息,请参阅 Power BI Desktop 入门To learn more about how to use Power BI Desktop, see Getting Started with Power BI Desktop.

Power BI Desktop 中,可以通过将数据的副本导入 Power BI Desktop 来连接数据源,或者使用 DirectQuery 直接连接数据源。With Power BI Desktop, you connect to your data source by importing a copy of the data into Power BI Desktop or connecting directly to the data source using DirectQuery.

以下是使用导入DirectQuery 之间的区别。Here are the differences between using Import and DirectQuery.

导入Import DirectQueryDirectQuery
将表、列和数据 导入或复制到 Power BI DesktopTables, columns, and data are imported or copied into Power BI Desktop. 当使用可视化效果时, Power BI Desktop 会查询数据的副本。As you work with visualizations, Power BI Desktop queries a copy of the data. 若要查看对基础数据所做的更改,必须刷新,或重新导入完整的当前数据集。To see any changes that occurred to the underlying data, you must refresh, or import, a complete, current dataset again. 仅将表和列 导入或复制到 Power BI DesktopOnly tables and columns are imported or copied into Power BI Desktop. 当使用可视化效果时, Power BI Desktop 查询基础数据源,这意味着始终可以查看当前数据。As you work with visualizations, Power BI Desktop queries the underlying data source, which means you're always viewing current data.

有关连接到数据源的详细信息,请参阅 连接到数据源For more about connecting to a data source, see Connect to a data source.

Power BI Desktop中保存工作后,会创建一个 PBIX 文件。After you save your work in Power BI Desktop, a PBIX file is created. 此文件包含报表。This file contains your report. 此外,如果导入数据,则 PBIX 包含完整数据集;而如果使用 DirectQuery,PBIX 只包含数据集架构。In addition, if you import data the PBIX contains the complete dataset, or if you use DirectQuery, the PBIX contains just a dataset schema. 使用 Power BI 导入 API以编程方式将 PBIX 部署到工作区。You programmatically deploy the PBIX into your workspace using the Power BI Import API.

备注

Power BI 工作区集合还有其他一些 API,用于更改数据集所指向的服务器和数据库,以及设置数据集用于连接数据库的服务帐户凭据。Power BI Workspace Collections have additional APIs to change the server and database that your dataset is pointing to and set a service account credential that the dataset will use to connect to your database. 请参阅 Post SetAllConnections(发布 SetAllConnections)Patch Gateway Datasource(修补网关数据源)See Post SetAllConnections and Patch Gateway Datasource.

使用 API 创建 Power BI 数据集和报表Create Power BI datasets and reports using APIs

数据集Datasets

可以使用 REST API 在 Power BI 工作区集合中创建数据集。You can create datasets within Power BI Workspace Collections using the REST API. 然后即可将数据推送到数据集中。You can then push data into your dataset. 这样即可在不需要 Power BI Desktop 的情况下处理数据。This allows you to work with data without the need of Power BI Desktop. 有关详细信息,请参阅 Post Datasets(发布数据集)。For more information, see Post Datasets.

报告Reports

可以通过 JavaScript API 直接在应用程序中基于数据集创建报表。You can create a report from a dataset directly in your application using the JavaScript API. 有关详细信息,请参阅在 Power BI 工作区集合中基于数据集创建新报表For more information, see Create a new report from a dataset in Power BI Workspace Collections.

另请参阅See Also

示例入门Get started with sample
在 Power BI 工作区集合中进行身份验证和授权Authenticating and authorizing in Power BI Workspace Collections
嵌入报表Embed a report
在 Power BI 工作区集合中基于数据集创建新报表 保存报表Create a new report from a dataset in Power BI Workspace Collections Save reports
Power BI DesktopPower BI Desktop
JavaScript 嵌入示例JavaScript Embed Sample

有更多问题?More questions? 试用 Power BI 社区Try the Power BI Community