如何使用 C# 以编程方式编辑 Power BI Desktop 文档参

How to edit Power BI Desktop document parameters or data sources programmatically with C#?(如何使用 C# 以编程方式编辑 Power BI Desktop 文档参数或数据源?)

本文介绍了如何使用 C# 以编程方式编辑 Power BI Desktop 文档参数或数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置在 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 中(搜索 RootFormulaTextReferencedQueriesFormulaText 文本以找到它们).服务器和数据库名称也在那里.您可以相对容易地修改 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 文档参数或数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何使用 C# 以编程方式编辑 Power BI Desktop 文档参

基础教程推荐