快速入门:使用 iFrame 和 URL 参数嵌入 Power BI 报表Quickstart: Embed a Power BI report using an iFrame and URL parameters

可以通过在应用程序中使用 iFrame 嵌入任何报表。You can embed any report by using an iFrame in your application.

URL 参数URL parameter

对于指向报表的任何 URL,可以添加查询字符串参数 ?rs:Embed=trueFor any URL to a report, you can add a querystring parameter of ?rs:Embed=true.

例如:For example:

http://myserver/reports/powerbi/Sales?rs:embed=true

这将适用于 Power BI 报表服务器中的所有报表类型。This will work on all report types within Power BI Report Server.

iFrameiFrame

有了 URL 后,可以在 Web 页面中创建 iFrame 来托管报表。Once you have your URL, you can create an iFrame within a web page, to host the report.

例如:For example:

<iframe width="800" height="600" src="http://myserver/reports/powerbi/Sales?rs:embed=true" frameborder="0" allowFullScreen="true"></iframe>

URL 筛选器URL filter

可以将查询字符串参数添加到 URL 来筛选在 Power BI 报表中返回的数据。You can add a query string parameter to the URL to filter the data that's returned in the Power BI report.

语法很简单;从报表 URL 入手,然后依次添加问号和筛选语法。The syntax is straightforward; start with the report URL, add a question mark, then this filter syntax.

URL?filter=/字段 eq ''URL?filter=Table/Field eq 'value'

请记住以下注意事项:Keep these considerations in mind:

  • 表和字段名称区分大小写,值不区分大小写。Table and Field names are case sensitive; value isn't.
  • 可以筛选字段在报表视图中隐藏的报表。You can filter a report with fields that are hidden from report view.
  • 必须用单引号将括起来。Value has to be enclosed with single quotes.
  • 字段类型必须是字符串。Field type has to be string.
  • 表和字段名称中不能有任何空格。Table and field names can't have spaces.

示例:筛选一个字段Example: Filter on a field

零售分析示例为例。Take for example the Retail Analysis sample. 假设这是报表服务器上名为“power-bi”的文件夹中的报告的 URL:Say this is the URL to the report on the report server in a folder called "power-bi":

https://report-server/reports/power-bi/Retail-Analysis-Sample

你会在零售分析示例中看到地图可视化效果,其中显示了北卡罗来纳州和其他州的商店。You see the map visualization in the Retail Analysis sample shows stores in North Carolina and other states.

零售分析示例地图可视化效果

NC 是存储在“Store”表的“Territory”字段中的北卡罗来纳州值。NC is the value for North Carolina stored in the Territory field of the Store table. 因此,要筛选报表以仅显示北卡罗来纳州商店的数据,请将以下内容附加到 URL 中:So to filter the report to show data only for stores in North Carolina, append the following to the URL:

?filter=Store/Territory eq 'NC'?filter=Store/Territory eq 'NC'

现在,报表针对北卡罗来纳州进行了筛选;报表页上的所有可视化效果都只显示北卡罗来纳州的数据。Now the report is filtered for North Carolina; all the visualizations on the report page show data for only North Carolina.

零售分析示例筛选可视化效果

创建 DAX 公式对多个值进行筛选Create a DAX formula to filter on multiple values

对多个字段进行筛选的另一方法是在 Power BI Desktop 中创建一个将两个字段合并成一个值的计算列。Another way to filter on multiple fields is by creating a calculated column in Power BI Desktop that concatenates two fields to a single value. 然后,便可以筛选此值。Then you can filter on that value.

例如,零售分析示例包含两个字段:Territory 和 Chain。For example, the Retail Analysis sample has two fields: Territory and Chain. 在 Power BI Desktop 中,可以创建一个计算列(字段),并将其命名为“TerritoryChain”。In Power BI Desktop, you can create a calculated column (Field) called TerritoryChain. 请注意,“字段”名称中不能有任何空格。Remember that the Field name can't have any spaces. 下面是此计算列的 DAX 公式。Here is the DAX formula for that column.

TerritoryChain = [Territory] & "-" & [Chain]TerritoryChain = [Territory] & "-" & [Chain]

将报表发布到 Power BI 报表服务器,然后使用 URL 查询字符串筛选出 NC 中 Lindseys 商店的数据。Publish the report to the Power BI Report Server, then use the URL query string to filter to display data for only Lindseys stores in NC.

https://report-server/reports/power-bi/Retail-Analysis-Sample?filter=Store/TerritoryChain eq 'NC-Lindseys'

后续步骤Next steps

快速入门:为 Power BI 报表服务器创建 Power BI 报表Quickstart: Create a Power BI report for Power BI Report Server
快速入门:为 Power BI 报表服务器创建分页报表Quickstart: Create a paginated report for Power BI Report Server

更多问题?More questions? 尝试咨询 Power BI 社区Try asking the Power BI Community