Forum Discussion

artlemaks's avatar
artlemaks
Icon for Helper II rankHelper II
6 years ago
Solved

Adding filters in Power BI Embedded with PHP and JS

I have a Power BI Embedded service running on my Azure instance. I have successfully embedded the report using CURL PHP and JS. The report loads fine.

I am now trying to add filters to the report. I have tried following an answer here How to set filters in reports power BI embedded javascript but I am getting an error

Uncaught SyntaxError: Missing initializer in const declaration

This is what my JS looks like for the basicFilter

  const basicFilter: pbi.models.IBasicFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "storemaster",
column: "customer_id"
},
operator: "In",
values: [<? echo $customer_id; ?>],
filterType: 1 // pbi.models.FilterType.BasicFilter
}

and then when generating the actual report

var embedConfiguration= {
type: 'report',
id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // the report ID
embedUrl: "<?php echo $embedUrl; ?>",
accessToken: "<?php echo $token; ?>" ,
filters: [basicFilter]
};

Where am I going wrong? I couldn't find any other answers to that question that would help with my problem.

  • I have contacted Power BI support and they have pointed me to Embedded Playground in order to test my code.

     

    While playing around there, I noticed one major difference in my code against Power BI. 

     

    I was using 

     

    const basicFilter: pbi.models.IBasicFilter = {

    While the correct syntax should be

    const basicFilter = { 

    I have made that change and now my report loads properly.  

3 Replies

  • v-xuding-msft's avatar
    v-xuding-msft
    Icon for Community Support rankCommunity Support

    It is weird. Generally, it is caused that we don't specify a value for a const declaration while encountering the error:  Uncaught SyntaxError: Missing initializer in const declaration.  But I check your code. It should work. 

     

    Please create a support ticket to get the dedicated support.

  • I have contacted Power BI support and they have pointed me to Embedded Playground in order to test my code.

     

    While playing around there, I noticed one major difference in my code against Power BI. 

     

    I was using 

     

    const basicFilter: pbi.models.IBasicFilter = {

    While the correct syntax should be

    const basicFilter = { 

    I have made that change and now my report loads properly.  

  • superxerox's avatar
    superxerox
    Regular Visitor

    How did you achieve Embedded power bi in PHP ?, I have days looking for documentation and I can't. I hope you can help me