Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
Hi community,
I'm working on a web application that redirects to a Power BI dashboard with Row-Level Security (RLS) applied. I want to improve the user experience by displaying a custom message instead of broken visuals when users lack access based on RLS. Ideally, the message would suggest contacting support (e.g., "Contact support team @ XYZ").
I tried to achieve this by using DAX measure but the visuals break.
Can anyone advise on how to achieve this? My current approach results in users seeing broken visuals, which isn't helpful.
Thanks,
AnthonyJoseph
Solved! Go to Solution.
Certainly! Let's break down the steps and provide some specific examples based on your scenario where you're using the userprincipal() function in your RLS setup.
Assuming you have a table in your Power BI dataset where you apply RLS using the userprincipal() function, here's how you can create a measure to display a custom message when users lack access:
Create a Measure:
Let's say your table is named Sales and you want to display a custom message in case the user doesn't have access to any data in this table. You can create a measure like this:
CustomMessage =
IF (
COUNTROWS ( 'Sales' ) > 0,
BLANK (), -- If the user has access to data, display nothing
"Contact support team @ XYZ" -- If the user doesn't have access, display custom message
)
This measure checks if there are any rows visible to the user in the 'Sales' table. If there aren't any rows visible, it displays your custom message.
Use in Visuals:
Place this measure in a card visual or any other suitable visual in your Power BI report. Users who lack access will see the custom message instead of broken visuals.
If you're embedding the Power BI report into a web application and want to handle cases where visuals are broken due to lack of access, you can use Javascript:
Embedding API Events:
Use the Power BI Embedding API to handle events such as errors. Here's a simplified example:
report.on("error", function(event) {
var errorCode = event.detail.code;
if (errorCode === 2006) { // Error code for access denied
displayCustomMessage("Contact support team @ XYZ");
}
});
function displayCustomMessage(message) {
// Write JavaScript code to display the message to the user
}
This code listens for errors in the report. If the error code corresponds to an access denied error, it displays your custom message.
Error Handling:
Implement error handling in your JavaScript code to catch errors related to access rights. When such errors occur, display your custom message instead of the broken visuals.
These are simplified examples based on your scenario. Depending on your specific setup and requirements, you may need to adapt these examples accordingly. Feel free to ask if you need further clarification or assistance with any specific part of the implementation!
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Hi @AnthonyJoseph ,
If I understand correctly, the issue is that you want to display custom message for users. Please try the following methods and check if they can solve your problem:
1.Create a measure that checks if the user has access to data.
NoDataMessage =
IF(
ISBLANK(SUM(Table[YourDataColumn])),
"Contact support team @ XYZ",
"Other measures here"
)
2.Create a card visual to display the message.
3.Set up the visual to only display when there is data available. Use the DAX formula to conditionally show the details.
4.Use the View as role feature in Power BI Desktop to test the result for different user roles.
Best Regards,
Wisdom Wu
Create a DAX Measure: You can create a DAX measure that evaluates whether the user has access to the data or not. If the user doesn't have access, the measure will return a message; otherwise, it will return the data.
Use the DAX Measure in Visuals: Instead of directly using the fields in your visuals, use the DAX measure you created. This measure will dynamically display the custom message or the data based on the user's access level.
Here's a basic example of how you can create such a DAX measure:
CustomMessage =
IF (
/* Condition to check if the user has access */
/* You need to replace this condition with your RLS logic */
<Your_RLS_Condition>,
/* If user has access, return data */
[Your Data Field],
/* If user doesn't have access, return custom message */
"Contact support team @ XYZ"
)
Replace <Your_RLS_Condition> with the appropriate logic that checks whether the user has access to the data based on your RLS rules.
Once you have created this measure, you can use it in your visuals instead of directly using the data fields. This way, users who don't have access will see the custom message instead of broken visuals.
Remember to adjust the RLS condition in the DAX measure according to your specific requirements and RLS setup. This might involve checking user roles, memberships, or other criteria to determine access.
If you encounter issues with visuals breaking, ensure that your DAX measure is correctly formulated and that it handles both cases (access granted and access denied) appropriately.
Let me know if you need further clarification or assistance!
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
Thank you for sharing the details @123abc . I tried to understand and follow your instructions but I couldnt understand it completely. Currently in my RLS I am just using the userprincipal () in a table, that filters the data...
It would be of much help, if you can provide some samples....please can you provide more guidance and help me.
Thanks,
AnthonyJoseph
Certainly! Let's break down the steps and provide some specific examples based on your scenario where you're using the userprincipal() function in your RLS setup.
Assuming you have a table in your Power BI dataset where you apply RLS using the userprincipal() function, here's how you can create a measure to display a custom message when users lack access:
Create a Measure:
Let's say your table is named Sales and you want to display a custom message in case the user doesn't have access to any data in this table. You can create a measure like this:
CustomMessage =
IF (
COUNTROWS ( 'Sales' ) > 0,
BLANK (), -- If the user has access to data, display nothing
"Contact support team @ XYZ" -- If the user doesn't have access, display custom message
)
This measure checks if there are any rows visible to the user in the 'Sales' table. If there aren't any rows visible, it displays your custom message.
Use in Visuals:
Place this measure in a card visual or any other suitable visual in your Power BI report. Users who lack access will see the custom message instead of broken visuals.
If you're embedding the Power BI report into a web application and want to handle cases where visuals are broken due to lack of access, you can use Javascript:
Embedding API Events:
Use the Power BI Embedding API to handle events such as errors. Here's a simplified example:
report.on("error", function(event) {
var errorCode = event.detail.code;
if (errorCode === 2006) { // Error code for access denied
displayCustomMessage("Contact support team @ XYZ");
}
});
function displayCustomMessage(message) {
// Write JavaScript code to display the message to the user
}
This code listens for errors in the report. If the error code corresponds to an access denied error, it displays your custom message.
Error Handling:
Implement error handling in your JavaScript code to catch errors related to access rights. When such errors occur, display your custom message instead of the broken visuals.
These are simplified examples based on your scenario. Depending on your specific setup and requirements, you may need to adapt these examples accordingly. Feel free to ask if you need further clarification or assistance with any specific part of the implementation!
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
15 | |
13 | |
11 | |
9 | |
8 |