問題描述
我有一個內置在 Power BI Desktop 中的報表模板,并保存為 .pbix 或 .pbit 文件.此模板使用 DirectQuery SQL 數據庫作為數據源,而將服務器地址和數據庫名稱提取到參數中.還有一個參數包含一個 ReportId
,用于查詢.
I have a report template which is built in Power BI Desktop and is saved as .pbix or .pbit file. This template uses DirectQuery SQL database as data source, whereas server address and database name are extracted to parameters. There is also a parameter which holds a ReportId
, which is used in queries.
我還有一個 C# 應用程序,它應該從這個模板生成 Power BI Desktop 報告.
如何以編程方式創建具有特定參數的報告?
當您打開 .pbit 模板文件、輸入參數并生成 .pbix 文檔時,Power BI Desktop 之類的東西會自行執行.
I also have a C# application, which is supposed to generate Power BI Desktop reports from this template.
How can create a report with specific parameters programmatically?
Something like Power BI Desktop does itself when you open .pbit template file, enter parameters and it generates .pbix document.
我沒有找到任何適用于 Power BI Desktop 的 SDK Interop 庫.
我嘗試以 ZIP 格式打開文檔,但 DataModel
文件已存檔,因此不是格式良好的 XML.
我也嘗試將此參數提取到 JSON 文件并將其作為數據源加載,但 Power BI 不支持相對路徑.
I didn't find any SDK Interop libraries for Power BI Desktop.
I have tried to open a document as ZIP, but DataModel
file is archived, and therefore not a well-formed XML.
I have also tried to extract this parameters to JSON file and load it as a data source, but relative paths are not supported by Power BI.
推薦答案
沒有可用于執行此操作的 SDK 或 API.如果將此報告發布到 Power BI Online,則可以使用 更新參數和更新組內參數 REST API 調用以更改參數值.我相信 Power BI Reporting Server 有類似的 API,但我沒有這方面的經驗.
There is no SDK or API you can use to do that. If you publish this report to Power BI Online, you can use Update Parameters and Update Parameters In Group REST API calls to change the parameter values. I believe Power BI Reporting Server has similar API, but I do not have experience with it.
您可以嘗試在線發布報告并保留(無需與任何人共享).當您需要帶有某個參數值的報告時,調用上面的 API 方法更改值,然后使用 導出報告 或 在組中導出報告 方法.它很丑陋且不是線程安全的,但可能會工作......
You could try to publish the report online and keep it there (it is not needed to share it with anyone). When you need a report with some parameter value, call the API methods above to change the value, and then download the modified .pbix file using Export Report or Export Report In Group methods. It's ugly and not thread safe, but may work...
您說您查看了提取的 .pbix 中的 DataModel
文件.我認為參數和 M 查詢在 DataMashup
中(搜索 RootFormulaText
或 ReferencedQueriesFormulaText
文本以找到它們).服務器和數據庫名稱也在那里.您可以相對容易地修改 M 查詢、現有參數的值或服務器/數據庫名稱,并嘗試重新打包 .pbix 文件.它可能有效,但看起來非常不受支持.
You said you looked at DataModel
file in the extracted .pbix. I think the parameters and M queries are in DataMashup
(search for RootFormulaText
or ReferencedQueriesFormulaText
text to find them). The server and database names are also there. You can relatively easy modify the M query, the value of existing parameter or server/database name, and try to re-pack the .pbix file. It may work, but looks extremely unsupported.
我嘗試在 Power BI Desktop 中將 SSMS 連接到報表的 SSAS,但我沒有找到以這種方式修改參數值的方法.不過,我可以在源查詢中看到它們的值(如果該參數用作過濾器).
I tried to connect with SSMS to the report's SSAS in Power BI Desktop, but I didn't find a way to modify parameter value this way. I can see their values in the source queries, though (if the parameter is used as a filter).
我正在使用類似的東西,但不是參數,而是將報告嵌入到我的應用程序中并使用 過濾器.這樣,所有用戶都可以訪問同一份報告,我不需要為他們的特定需求定制".pbix.
I'm using something similar, but instead of parameters, I'm embedding the report in my application and use filters. This way all users access one and the same report and I do not need to "tailor" the .pbix for their specific needs.
恐怕這不是一個能解決你問題的答案,但我希望它能給你一些想法,你能做什么或不能做什么!
I'm afraid this isn't an answer that will solve your problem, but I hope it will give you some ideas what you can or can't do!
這篇關于如何使用 C# 以編程方式編輯 Power BI Desktop 文檔參數或數據源?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!