Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
kevinbrad06
Frequent Visitor

Custom Visual with Shared Dataset

I've created a custom visual that filters the dataset based on user provided values. Everything works greats in my main report published to the service.

 

However, I have several reports that use the same dataset as their source. In those other reports the filters appear to fire (visuals refresh) but no data is filtered out. Has anyone experienced this? I'm a very novice developer but I believe these are the lines that are causing problems.

 

let target: IFilterColumnTarget = {
table: categories.source.queryName.substr(0, categories.source.queryName.indexOf('.')), // table
column: categories.source.displayName // col1
};
let filter: IBasicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
...(new BasicFilter(
target,
"In",
listItem
))
};

// invoke the filter
this.host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);

Any help would be much appreciated.

 

**Edited to Add Capabilities.json

{
"dataRoles": [
{
"displayName": "Filter Column",
"name": "values",
"kind": "Grouping"
}
],
"dataViewMappings": [
{
"conditions": [
{
"values": {
"max": 1
}
}
],
"categorical": {
"categories": {
"for": {
"in": "values"
},
"dataReductionAlgorithm": {
"top": {
"count": 100000
}
}
}
}
}
],
"objects": {
"general": {
"displayName": "General",
"properties": {
"filter": {
"displayName": "filter",
"type": {
"filter": true
}
}
}
}
}
}
1 ACCEPTED SOLUTION

Thank you for your help. It ended up being an extremely easy solution this was just my first attempt at a custom viz. I was using the displayName to pass in the column to be filtered and of course there are scenarios where the user has changed the display name. I grabbed the column name from the query name instead and it is working great.

 

View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

Hi @kevinbrad06

It's hard to offer any solid advice with debugging slicers/filters as they are very data-dependent. You can send a set of criteria to the filter API, but Power BI will look at all the available contexts in other visuals on the page and actually determine if the filters are needed, so what you send may not always be applied. If other visuals on the the page should be affected contextually, then this is some cause for concern.

Are you absolutely sure that the filter you're sending has the correct info for Power BI? Assuming you're able to debug your visual against these reports and try to repeat your users' actions, then it might be worth logging the filter object to the browser console using JSON.stringify() or similar to inspect in finer detail.

It is possible that if, for example, null values, or an incorrect property chain when resolving your listItem array from the visual might result in filter values that Power BI can't resolve when it receives your request. This part of the code is not in your OP, unfortunately.

If the above output looks okay from your end, then we might need some more of your code, and possibly some sample data (and a sample of the filter object output) to try and debug further.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Thank you for your help. It ended up being an extremely easy solution this was just my first attempt at a custom viz. I was using the displayName to pass in the column to be filtered and of course there are scenarios where the user has changed the display name. I grabbed the column name from the query name instead and it is working great.

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.