快速入門:使用 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=true 的查詢字串參數。For 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 之後,您可以在網頁內建立 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