Forum Discussion
UDF User Data Function - error when user has not access to function
- 1 year ago
Hey SnoekLaurens ,
Since you're using the new native writeback functionality in Microsoft Fabric with UDF and not using Power Automate or Power Query, the solution should focus on enhancing the button’s behavior directly in Power BI. Steps to Add Error Handling to the Button:
Create a DAX Measure for User Permissions: First, create a DAX measure that checks whether the current user has the necessary permissions. This could be based on roles or a user table that tracks access levels.
UserHasPermission = IF( CONTAINS( UserPermissions[UserID], UserPermissions[UserID], USERNAME() ), TRUE, FALSE )Set the Button Action Based on the Permission Check:
You can use the UserHasPermission measure in the button’s Action property to control whether the UDF is triggered.
If the user does not have permission, you can set the button action to None or show a message indicating lack of access.
Use a Dynamic Tooltip/Message: You can also configure the button’s tooltip or dynamic text to inform the user about their permission status.
ButtonMessage = IF( [UserHasPermission] = TRUE(), "Click to writeback to Fabric Warehouse", "You do not have permission to perform this action" )Provide Feedback on the Button: Set the Visible property of the button based on the permission measure:
ButtonVisible = IF([UserHasPermission] = TRUE(), TRUE(), FALSE())
This way, the button can either be visible or hidden depending on the user's access level.
Implement these DAX measures in your Power BI report and link them to the button properties like Action, Visible, and Tooltip to manage user interactions based on their permissions.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
I'm using the new native writeback capability with the new UDF function in Microsoft Fabric so I'm not using Power Automate and also Power Query is not directly used for this purpose.
So option 3 seems suitable but I have no idea how to do that in Power BI. I have a button with the data function connected. How can I add this to that button?
Hey SnoekLaurens ,
Since you're using the new native writeback functionality in Microsoft Fabric with UDF and not using Power Automate or Power Query, the solution should focus on enhancing the button’s behavior directly in Power BI. Steps to Add Error Handling to the Button:
Create a DAX Measure for User Permissions: First, create a DAX measure that checks whether the current user has the necessary permissions. This could be based on roles or a user table that tracks access levels.
UserHasPermission = IF( CONTAINS( UserPermissions[UserID], UserPermissions[UserID], USERNAME() ), TRUE, FALSE )Set the Button Action Based on the Permission Check:
You can use the UserHasPermission measure in the button’s Action property to control whether the UDF is triggered.
If the user does not have permission, you can set the button action to None or show a message indicating lack of access.
Use a Dynamic Tooltip/Message: You can also configure the button’s tooltip or dynamic text to inform the user about their permission status.
ButtonMessage = IF( [UserHasPermission] = TRUE(), "Click to writeback to Fabric Warehouse", "You do not have permission to perform this action" )Provide Feedback on the Button: Set the Visible property of the button based on the permission measure:
ButtonVisible = IF([UserHasPermission] = TRUE(), TRUE(), FALSE())
This way, the button can either be visible or hidden depending on the user's access level.
Implement these DAX measures in your Power BI report and link them to the button properties like Action, Visible, and Tooltip to manage user interactions based on their permissions.
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam
- SnoekLaurens1 year agoAdvocate I
Making the button invisible when a user doesn't have access sounds like a good option.
But I do not want to maintain a seperate table with the permission per user.
Can I dynamically check whether the user has access or get the user permission table via REST API somehow?- v-priyankata1 year agoCommunity Support
Hi SnoekLaurens
Thank you for reaching out to the Microsoft Fabric Forum Community.
Power BI doesn’t let you check user permissions in real time when someone clicks a button. It can’t call APIs like Microsoft Graph or Fabric Admin while the report is open, so you can’t instantly know if someone has access to the UDF at that moment.
What you can do is set up something that runs in the background, maybe every hour or once a day that gets the list of users who should have access (from a security group or workspace). You save that list into a table in your Fabric warehouse, and then use it in Power BI. This way, you can use a DAX formula to show or hide the writeback button depending on who’s logged in.
If this information is helpful, please “Accept as solution” to assist other community members in resolving similar issues more efficiently.
Thank you.- v-priyankata1 year agoCommunity Support
Hi SnoekLaurens
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.