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 !!
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 : “http://powerbi.com/product/schema#basic”,
target : {
table : “the table name in your dataset”,
column : “T Number”,
},
operator : “=”,
values : [tnum]
}
];
</script>
<b>
“<“ul”>”
“<“li”>”
“<“a href=”http://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 6 years, 2 months ago by
zara59.
-
This reply was modified 6 years, 2 months ago by
zara59.
Thread Starter
zara59
(@zara59)
< a href=”http://YourSiteName/View Report/”
onclick=”location.href=this.href+’?filters=’+encodeURIComponent(JSON.stringify(relatedFilterObj));return false;”>View Report
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?
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.