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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
skancharla
Advocate II
Advocate II

Two advanced date filters with javascript api

Hi,

 

I have two visuals Line chart and a bar chart in a page with columns Release month and Release date respectively.

 

I'm trying to filter these visuals with javascript api. Both are advanced filter schema. I'm able to apply them indiviually but not both of them together at the same time.Getting invalid filter definition error

 

Have verified the date formats i'm using and are correct.Cant we apply two advanced date filters at the same time.

Any help is highly appreciated.No luck on this inspite of mulitple trys and efforts.

 

var monthFilter = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Line Chart",
column: "ReleaseMonth"
},
logicalOperator: "AND",
conditions: [
{
operator: "GreaterThanOrEqual",
value: convertDate(selectedFromDate) + "T00:00:00.000Z"
},
{
operator: "LessThanOrEqual",
value: convertDate(selectedToDate) + "T00:00:00.000Z"
}
]
}

var dateFilter = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Query1",
column: "ReleaseDate"
},
logicalOperator: "AND",
conditions: [
{
operator: "GreaterThanOrEqual",
value: convertDate(selectedFromDate) + "T00:00:00.000Z"
},
{
operator: "LessThanOrEqual",
value: convertDate(selectedToDate) + "T00:00:00.000Z"
}
]
}

 

filters.push(monthFilter);
filters.push(dateFilter);
report.setFilters(filters);

2 REPLIES 2
balachaitanya
New Member

Facing very similar issue.

 

fromdatefilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "MyData",
column: "ORDER_CREATION_DATE"
},
operator: "GreaterThan",
values: fromDateValue

 

};

 

Any specific format to be given for Date? Other integer and string filters seem to work.

 

Eric_Zhang
Microsoft Employee
Microsoft Employee

@skancharla

I don't get the invalid filter denition and based on my test, applying two advanced filter shall work.

 

<html>

 <script src="https://microsoft.github.io/PowerBI-JavaScript/demo/bower_components/jquery/dist/jquery.js"></script>  
 <script src="https://microsoft.github.io/PowerBI-JavaScript/demo/bower_components/powerbi-client/dist/powerbi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ODhiZi04NmYxLTQxYWYtOTFhYi0yZDdjZDAxMWRiNDciLCJ1bmlxdWVfbmFtZSI6InYtbHZ6aGFuQG1pY3Jvc29mdC5jb20iLCJ1cG4iOiJ2LWx2emhhbkBtaWNyb3NvZnQuY29tIiwidmVyIjoiMS4wIn0.vGL9W6DDkLTMLLKqI76nrh4wOBFYaEFKjy0ile7XS1X46oEtdDRBCbfhnB9FhkbTlW0_vS4JC7Uz1XyPjirKlZr31OMDU-3avGWP_ynx4pCkUw0qSiwUBsWdWsNXfgFe46jDnw225yQfgU3gSjDkN578SBA13QFRVFZthdtBmk09Yhdp79v4lUYmec3GuDY2wTn1hjpCoBr60V5Z7WPBsyDfHw_s6gKGJQCGNgK1xCJQGUo2gVVsxegrlT4J2nQoeCnMis-7sNytWCH4vIM1VkoXSTojtegfUjzoAvN8LDWO242kGDQ4gH2Y7hQJsGzOV3I2gGBZo7As1oerU0tyvA',
    id: 'cd8856d7-f92e-XXXX-XXXX-5eaec904288f',
    embedUrl: 'https://app.powerbi.com/reportEmbed?reportId=cd8856d7-f92e-XXXX-XXXX-5eaec904288f' 
}; 

var report;

window.onload = function () { 

var $reportContainer = $('#reportContainer');
 
 report= powerbi.embed($reportContainer.get(0), embedConfiguration);
 
 
 var Filter1 = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table1",
column: "T1id"
},
logicalOperator: "OR",
conditions: [
{
operator: "Contains",
value: "id1"
} 
]
}

var Filter2 = {
$schema: "http://powerbi.com/product/schema#advanced",
target: {
table: "Table2",
column: "T2id"
},
logicalOperator: "OR",
conditions: [
{
operator: "Contains",
value: "id1"
} 
]
}

report.on('loaded', event => {
  report.getFilters()
    .then(filters => {
	
      filters.push(Filter1);
      filters.push(Filter2);
      return report.setFilters(filters);
    });
});
 
} 


function reloadreport(){ 

var $reportContainer = $('#reportContainer');
powerbi.embedNew($reportContainer.get(0), embedConfiguration);

};
</script>
 


<button onclick="reloadreport()">Click me to refresh</button>
<div id="reportContainer"></div>

</html>  

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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