Forum Discussion
Filter iFrame in Dynamics based on user logged in
I'm looking to embed Power BI reports in Dynamics using an iFrame. The goal is to have the reports automatically filter to show records owned by the logged-in user.
Does anyone have experience with this?
Thanks in advance!
2 Replies
- FarhanJeelani
Super User
Hi AnneSophieD_ ,
To embed Power BI reports in Dynamics using an iFrame and have them automatically filter records based on the logged-in user, follow these steps:
1. Set Up Row-Level Security (RLS) in Power BI
- Create roles in Power BI to filter data by user. For example:
[OwnerEmail] = USERPRINCIPALNAME()
- Replace [OwnerEmail] with the column in your data that stores the user's email or identifier.
- Assign this role in Power BI to dynamically filter data for the logged-in user.
2. Publish the Power BI Report
- Publish the report to your Power BI workspace.
3. Ensure Data Permissions Are Properly Configured
- Assign the correct roles to users in the Power BI service:
- Go to the Security tab for the dataset in Power BI.
- Add users or groups to the appropriate RLS role.
4. Get the Report URL
- In the Power BI service, go to the report and copy the Embed URL for the web.
5. Configure the Dynamics iFrame
- In Dynamics 365, navigate to the form or dashboard where you want to embed the report.
- Add an iFrame to the form:
- Open the form editor.
- Insert an iFrame control and set the URL to the Power BI Embed URL.
- Pass the current user's email or identifier as a filter parameter in the URL:
https://app.powerbi.com/reportEmbed?reportId=...&filter=TableName/ColumnName eq 'CurrentUserValue'
Replace:- TableName/ColumnName with the table and column you want to filter on.
- CurrentUserValue with a placeholder for the logged-in user (see next step).
6. Pass the Logged-In User's Context
- Use Dynamics' JavaScript to dynamically inject the logged-in user's value (e.g., email) into the iFrame URL. For example:
function setIframeUrl(executionContext) { var formContext = executionContext.getFormContext(); var loggedInUser = Xrm.Utility.getGlobalContext().userSettings.userName; // Or userId var iframeControl = formContext.getControl("IFRAME_ControlName"); var reportUrl = "https://app.powerbi.com/reportEmbed?reportId=...&filter=TableName/ColumnName eq '" + loggedInUser + "'"; iframeControl.setSrc(reportUrl); }- Replace IFRAME_ControlName with the name of your iFrame control.
7. Test the Integration
- Save and publish the form/dashboard in Dynamics.
- Open the form as a user and verify the Power BI report filters correctly based on the logged-in user's data.
Notes:
- Make sure the Dynamics and Power BI users have matching identifiers (e.g., email or UPN) for filtering.
- Ensure the users have appropriate permissions in both Dynamics and Power BI to access the data and reports.
Please mark this as solution if it helps. Appreciate Kudos.
- Create roles in Power BI to filter data by user. For example:
- AnonymousNot applicable
Hi AnneSophieD_ ,
Did the above reply help you? If so, please accept it.
In addition, this blog provides a comprehensive overview of different methods to embed Power BI in Dynamics 365, including security considerations and step-by-step instructions.
Study of Power BI embedded integration in Dynamics 365
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.