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

查看:622
本文介绍了如何使用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模板文件时,类似于Power BI Desktop的操作,输入参数,然后生成.pbix文档。

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.

我没有找到任何SDK Power Power BI Desktop的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...

您说过您看过文件中的 DataModel 文件提取.pbix。我认为参数和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.

我试图将SSMS连接到Power BI Desktop中报表的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文档参数或数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆