是否可以通过使用 power bi rest api 过滤来获取报告? [英] Is it possible to get reports by filtering using power bi rest api?
问题描述
是否可以通过使用 power bi rest api 进行过滤来获取报告?我想嵌入按记录过滤的 power bi 报告.我在 power bi rest api 上看不到任何选项,那么如何通过过滤器获取所有报告并将报告嵌入到我的应用程序中?
Is it possible to get reports by filtering using power bi rest api? I want to embed power bi reports filtering by records. I can't see any option on power bi rest api, then how to get all reports by filter and embed reports in my application?
由于我使用 powerbi.js 作为 javascript 客户端,所以下面是我的示例代码:https://github.com/Microsoft/PowerBI-JavaScript
Since I am using powerbi.js as javascript client so below is my sample code: https://github.com/Microsoft/PowerBI-JavaScript
var tokenType = 'embed';
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// We give All permissions to demonstrate switching between View and
//Edit mode and saving report.
var permissions = models.Permissions.All;
var config = {
type: 'report',
tokenType: tokenType == '0' ? models.TokenType.Aad :
models.TokenType.Embed,
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
id: txtEmbedReportId,
permissions: permissions,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};
// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
// Embed the report and display it within the div container.
var report = (<any>window).powerbi.embed(embedContainer, config);
推荐答案
嵌入报表时,可以使用 嵌入配置 以在加载报告时应用过滤器.您也可以稍后动态更改过滤器.
When you are embedding a report, you can use the Embed Configuration to apply filters when the report is loaded. You can also change the filters dynamically later.
这里引用了 过滤器维基:
过滤器是具有一组特殊属性的 JavaScript 对象.目前,有五种类型的过滤器:Basic
、Advanced
、Relative Date
、Top N
和 包含/排除
,它们与您可以通过过滤器窗格创建的过滤器类型相匹配.对应的接口有IBasicFilter
、IAdancedFilter
、IRelativeDateFilter
、ITopNFilter
和IIncludeExcludeFilter
,分别是描述它们所需的属性.
Filters are JavaScript objects that have a special set of properties. Currently, there are five types of filters:
Basic
,Advanced
,Relative Date
,Top N
andInclude/Exclude
, which match the types of filters you can create through the filter pane. There are corresponding interfacesIBasicFilter
,IAdvancedFilter
,IRelativeDateFilter
,ITopNFilter
andIIncludeExcludeFilter
, which describe their required properties.
例如,您的过滤器可以这样构造:
For example, your filter can be constructed like this:
const basicFilter: pbi.models.IBasicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "Sales",
column: "AccountId"
},
operator: "In",
values: [1,2,3],
filterType: pbi.models.FilterType.BasicFilter
}
您应该在报告的配置 filters
属性中传递此过滤器.
You should pass this filter in report's configuration filters
property.
这篇关于是否可以通过使用 power bi rest api 过滤来获取报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!