Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have read several posts and tried many examples and none of them are filtering my report. Below are a couple examples. Please help.
var accessToken = "@Model.EmbedToken.Token";
// Read embed URL from Model
var embedUrl = "@Html.Raw(Model.EmbedUrl)";
// Read report Id from Model
var embedReportId = "@Model.Id";
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// Get a reference to the embedded report HTML element
var reportContainer = $('#embedContainer')[0];
if ("@Model.Username" != "") {
$("#RLS").prop('checked', true);
$("#RLSdiv").show();
}
else
{
$("#RLS").prop('checked', false);
$("#RLSdiv").hide();
}
if ("@Model.IsEffectiveIdentityRequired.GetValueOrDefault()" == "True") {
$("#noRLSdiv").hide();
$("#RLS").removeAttr("disabled");
$("#RLS").change(function () {
if ($(this).is(":checked")) {
$("#RLSdiv").show(300);
} else {
$("#RLSdiv").hide(200);
}
});
}
else
{
$("#noRLSdiv").show();
}
const testFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "SampleParameter",
column: "AgentID"
},
operator: "In",
values: ["H1627"]
};
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
permissions: models.Permissions.All,//models.Permissions.Read
//can add filters here
filters: [testFilter], //filter array here
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true //the nav at bottom of report
},
//filterType: models.FilterType.BasicFilter
};
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
// Build the filter you want to use. For more information, See Constructing
// Filters in https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters.
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "SampleParameter",
column: "AgentID"
},
operator: "In",
values: ["H1627"]
};
// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
// Set the filter for the report.
// Pay attention that setFilters receives an array.
report.setFilters([filter])
.then(function () {
Log.logText("Report filter was set.");
})
.catch(function (errors) {
Log.log(errors);
});
Solved! Go to Solution.
Data Model:
Filter from design time in Power BI Desktop (but I can remove this and remember I mentioned that other columns not already added do not work):
Yes the value exists and yes the filter works as expected. Is anything else required?
Hi @jrichardsherita
I can see one potential issue...
The filter object doesn't contain a 'filterType' property. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Filters
I have a working example that effectively matches what you have... with that one exception.
Filter types are as follows:
export enum FilterType {
Advanced = 0,
Basic = 1,
Unknown = 2,
IncludeExclude = 3, // currently not supported
RelativeDate = 4,
TopN = 5,
Tuple = 6,
RelativeTime = 7
}
So your full example should be:
const testFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "SampleParameter",
column: "AgentID"
},
operator: "In",
values: ["H1627"],
filterType: 1
};
If you are using TypeScript - you can also reference the pbi.models enum values for these
filterType: pbi.models.FilterType.Basic
Hopefully this fixes it.
Thank you very much for the reply. Unfortuneately, that does not fix the issue. What happens is this filter puts 'AgentID' in the 'Filters on all pages' pane with a warning icon and obviously the report is not filtered. Using developer tools, that icon has a symbolid="fieldListError" and href="#fieldListError". I do not know what that means. I can change the filter to another column on the report and I will get the same issue. The code is in javascript. Is more content needed? Any other suggestions?
It's a bit tricky to diagnose without seeing the data model and relationships etc...
A couple of questions though...
Does that filter (AgentID) already exist as an available filter in the filter panel? (e.g. is it there at design time in Power BI Desktop)
And does the value that you are supplying exist within the available options -> Is it listed if you add the field as a filter in Power BI Desktop. + Does the filter work as expected (outside of the embedded environment)?
Data Model:
Filter from design time in Power BI Desktop (but I can remove this and remember I mentioned that other columns not already added do not work):
Yes the value exists and yes the filter works as expected. Is anything else required?
In your code sample, the table/column values are set to 'SampleParameter' + 'AgentID'
Your data model shows that field belonging to a table called 'ADW Agent DimCom....'
You will need to make sure that the table/column names are correct before anything else.
If this isn't the issue... then I will try and spend a few minutes later on today - and try and replicate what you are seeing.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
25 | |
3 | |
2 | |
2 | |
2 |