连接到数据源Connect to a data source

使用 Power BI 工作区集合,可以在自己的应用中嵌入报表。With Power BI Workspace Collections, you can embed reports into your own app. 在应用中嵌入 Power BI 报表时,可以通过 导入 数据的副本或通过使用 DirectQuery 直接连接 到数据源将该报表连接到基础数据。When you embed a Power BI report into your app, the report connects to the underlying data by importing a copy of the data or by connecting directly to the data source using DirectQuery.

Important

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.

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

导入Import 直接连接DirectQuery
将表、列 和数据 导入或复制到报表的数据集。Tables, columns, and data are imported or copied into the report's dataset. 若要查看对基础数据所做的更改,必须刷新,或重新导入完整的当前数据集。To see changes that occurred to the underlying data, you must refresh, or import, a complete, current dataset again. 仅会将表和列导入或复制到报表的数据集中。Only tables and columns are imported or copied into the report's dataset. 始终可以查看最新的数据。You always view the most current data.

通过 Power BI 工作区集合,可以将 DirectQuery 与云数据源结合使用,但暂不能与本地数据源结合使用。With Power BI Workspace Collections, you can use DirectQuery with cloud data sources but not on-premises data sources at this time.

Note

Power BI 工作区集合暂不支持本地数据网关。The On-Premises Data Gateway is not supported with Power BI Workspace Collections at this time. 这意味着无法将 DirectQuery 与本地数据源配合使用。This means you cannot use DirectQuery with on-premises data sources.

支持的数据源Supported data sources

DirectQueryDirectQuery

  • Azure SQL 数据库Azure SQL database
  • Azure SQL 数据仓库Azure SQL Data Warehouse

导入Import

可使用 Power BI Desktop 内的所有可用数据源进行导入。You can import using all of the available data sources within Power BI Desktop. 不能在 Power BI 工作区集合中刷新此类数据。You will not be able to refresh that data within Power BI Workspace Collections. 必须将 PBIX 文件更改上传到 Power BI 工作区集合。You have to upload changes to your PBIX file to Power BI Workspace Collections. 这是因为没有可用的网关。This is due to no available gateway.

使用 DirectQuery 的优点Benefits of using DirectQuery

使用 DirectQuery具有两个主要优点:There are two primary benefits when using DirectQuery:

  • 使用 DirectQuery,可以根据大型数据集生成可视化效果,这就导致以其他方式先导入所有数据变得不可行。DirectQuery lets you build visualizations over large datasets, where it otherwise would be unfeasible to first import all of the data.
  • 基础数据更改可能需要刷新数据,对于一些报表,可能需要执行大型数据传输,才能显示当前数据,这就导致重新导入数据变得不可行。Underlying data changes can require a refresh of data, and for some reports, the need to display current data can require large data transfers, making reimporting data unfeasible. 与此相反, DirectQuery 报表始终使用当前数据。By contrast, DirectQuery reports always use current data.

DirectQuery 的限制Limitations of DirectQuery

使用 DirectQuery存在一些限制:There are a few limitations to using DirectQuery:

  • 所有表必须都来自单一数据库。All tables must come from a single database.
  • 如果查询过于复杂,则会出错。If the query is overly complex, an error occurs. 若要修复此错误,则必须重构查询,降低其复杂程度。To remedy the error you must refactor the query so it is less complex. 如果查询必须很复杂,需要导入数据,而不使用 DirectQuery。If the query must be complex, you need to import the data instead of using DirectQuery.
  • 关系筛选仅限于单向,而不是双向。Relationship filtering is limited to a single direction, rather than both directions.
  • 不能更改某列的数据类型。You cannot change the data type of a column.
  • 默认情况下,对度量值中允许使用的 DAX 表达式加以限制。By default, limitations are placed on DAX expressions allowed in measures. 请参阅 DirectQuery 和度量值See DirectQuery and measures.

DirectQuery 和度量值DirectQuery and measures

为了确保发送到基础数据源的查询具有可接受的性能,针对度量值施加了一些限制。To ensure queries sent to the underlying data source have acceptable performance, limitations are imposed on measures. 使用 Power BI Desktop 时,高级用户可以通过选择“文件”>“选项和设置”>“选项”来选择绕过此限制。When using Power BI Desktop, advanced users can choose to bypass this limitation by choosing File > Options and settings > Options. 在“选项”对话框中,选择“DirectQuery”,然后选择“允许 DirectQuery 模式下的度量值不受限制”选项。In the Options dialog, choose DirectQuery, and select the option Allow unrestricted measures in DirectQuery mode. 选中该选项后,可以使用对度量值有效的任何 DAX 表达式。When that option is selected, any DAX expression that is valid for a measure can be used. 不过,用户必须知道,虽然一些表达式在导入数据时性能很好,但在 DirectQuery 模式下可能会导致对后端源的查询非常缓慢。Users must be aware; however, that some expressions that perform well when the data is imported may result in slow queries to the backend source when in DirectQuery mode.

另请参阅See Also

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