• Hi
    Thanks for making this plugin. I’ve been using it for a while now and it’s perfect. But recently I need to use filter to filter my page based on some parameters but I can’t figure out where to insert this javascript code in the samples:

    var relatedFilterObj = [{
    $schema : “https://powerbi.com/product/schema#basic”,
    target : {
    table : “Countries”,
    column : “Country”,
    },
    operator : “=”,
    values : [country]

    }
    ];

    var relatedURL = pageURL + “?filters=” + encodeURIComponent(JSON.stringify(relatedFilterObj));<h3>Applying Slicers</h3>The plugin can also apply Slicers before the report loads based on passing stringified JSON in the URL. Read more about [Slicers](https://github.com/Microsoft/PowerBI-JavaScript/wiki/Slicers)

    Thanks
    Zara

Viewing 8 replies - 1 through 8 (of 8 total)
  • I’m facing same situtation Zara. If you or somebodyelse find any solution I ‘ll really appreciate to share it.

    Thanks!

    I have the same problem…. please help us to easy create url filter ? witch part of php code we have to modify ? an other way ?

    Thanks !!

    rincewind50

    (@rincewind50)

    I have just installed PowerBI embedded for WordPress and need to apply a filter.
    It is definitely not clear how to apply the code in WordPress. Does anyone have thoughts on this

    Thread Starter zara59

    (@zara59)

    Hi
    I managed to do it:
    In my application I get the userid of the logged in user and pass it to my power bi report to filter the results. I keep the useid in user’s display name in WordPress.

    I use XYZ PHP Code plugin to add php code to my pages.
    I added this code to a page(using XYZ PHP Code) and create the link to view the reports on the fly:

    <?php
    $current_user = wp_get_current_user();
    ?>

    <script type=”text/javascript”>

    var tnum= “<?php echo $current_user->display_name ?>”;

    var relatedFilterObj = [{
    $schema : “https://powerbi.com/product/schema#basic&#8221;,
    target : {
    table : “the table name in your dataset”,
    column : “T Number”,
    },
    operator : “=”,
    values : [tnum]

    }
    ];

    </script>
    <b>
    “<“ul”>”

    “<“li”>”
    “<“a href=”https://YourWordpressSiteName/ReportPage/”>View Report</a”>”
    “<“/li”>”

    “<“/ul”>”
    </b>

    In your report page simply embed the power bi report:
    [powerbi id=”id” width=”100%” height=”1080px”]

    Please let me know if it helps.
    Zara

    • This reply was modified 5 years ago by zara59.
    • This reply was modified 5 years ago by zara59.
    Thread Starter zara59

    (@zara59)

    < a href=”https://YourSiteName/View Report/”
    onclick=”location.href=this.href+’?filters=’+encodeURIComponent(JSON.stringify(relatedFilterObj));return false;”>View Report

    rincewind50

    (@rincewind50)

    Hi Zara59.

    I tried your example and I could not get it to work. I added your code with my elements to a page using XYZ PHP code, as well as the link code. I added the powerbi shortcode to another page.
    However, when I click on the link it does not pass the query string parameter to the page URL.

    I checked the page source on the page that has the php code and it does not populate variable tnum is empty. It does not seem to be picking up the current user.

    Any other thoughts

    Thread Starter zara59

    (@zara59)

    Hi

    I’m reading tnum from user’s display name per code below:
    var tnum= “<?php echo $current_user->display_name ?>”;

    In the user management admin panel, did you store userid in the user’s display name?

    rincewind50

    (@rincewind50)

    Hi.

    I sorted out the value of the tnum.

    However, in the link to the report page

    <a href=”https://permaas.com/permaas-users/permaas-user-results/”
    onclick=”location.href=this.href+’?filters=’+encodeURIComponent(JSON.stringify(relatedFilterObj));return false;”>View Report</a”>

    It is not passing the parameters in the query string to the report page. Still got to figure whay that is.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to use filter’ is closed to new replies.