Forum Discussion
Data function Button for running User Defined Function (UDF) is not configurable
- 8 months ago
HI SamSantos,
You're not doing anything wrong β this is a known limitation and partial rollout issue with Power BI Desktop + Fabric Data Functions, This feature is NOT fully available in Power BI Desktop yet.
You can try enabling below options in power BI desktop
Power BI Desktop β Options β Preview
Data functions
Fabric Business Operations
Write-back
Direct Lake (if needed)
if it doesn't work, you can edit the UDF in Power BI service and test.
π I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
π‘ Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
π As a proud SuperUser and Microsoft Partner, weβre here to empower your data journey and the Power BI Community at large.
π Curious to explore more? [Discover here].
Letβs keep building smarter solutions together! - 8 months ago
Hi grazitti_sapna, thanks for this detail! Yes, when i published the workbook to my workspace and editted the report online, the Data Funciton options were made available to me. I did not realize that this was currently an online only function.
Hi SamSantos,
maybe its worse checking out the limitations of UDFs here. Just to varify if you have one of these applied.
If not I would consider checking the syntax of your UDF, as in my case in the beginning this was the issue. Here a code of mine which acutally works and then shows the fields/parameters in Power BI:
import fabric.functions as fn
import uuid
udf = fn.UserDataFunctions()
# ===============================
# UDF: update_defect_resolution
# ===============================
# Take a defect id, resolver, resoltuion notes and parts replaced (Status will be set automatically to "closed" as this is the intended action) as input parameters
# Write the data back to the SQL database
# Users will provide these parameters in the PowerBI report
@udf.connection(argName="sqlDB",alias="DBSTOREDemo")
@udf.function()
def update_defect_resolution(sqlDB: fn.FabricSqlConnection,
defectid: int,
resolvedby: str,
resolutionnotes: str,
partsreplaced: str) -> str:
"""
Updates defect tracking record in the operational SQL database.
Status is default set to "Closed" if a resolution is entered.
Parameters:
-----------
defectid : int
Unique identifier of the defect record.
resolvedby : str
Name or ID of the maintenance worker.
resolutionnotes : str
Description of how the defect was resolved.
partsreplaced : str
Comma-separated list of parts replaced.
Returns:
--------
str
"Defect resolution updated successfully."
"""
try:
# Establish a connection to the SQL database
connection = sqlDB.connect()
cursor = connection.cursor()
# Update query
query = """
UPDATE [maintenance_demo].[defect_tracking]
SET resolved_by = ?,
resolution_notes = ?,
parts_replaced = ?,
status = 'Closed',
resolution_timestamp = GETUTCDATE()
WHERE defect_id = ?
"""
# Execute update
cursor.execute(query, (resolvedby, resolutionnotes, partsreplaced, defectid))
# Commit the transaction
connection.commit()
cursor.close()
connection.close()
return "Defect resolution updated successfully."
except Exception as e:
return {
"defect_id": defectid,
"status": "Error",
"message": str(e)
}
If this also does not help I recommend checking out the tutorial example as this have to work out anyway. If this also does not work I assume maybe some configuration is missing or it is indeed a issue somewhere in your environment and I recommend opening a issue to Microsoft to help you out.
You can submit a ticket via the Microsoft Power BI Support Portal:
How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn
Best regards!
PS: If you find this post helpful consider leaving kudos or mark it as solution
I appreciate the example, I'll give it a test. When you say you had syntax issues, do you mean you were able to get the UDF to run but not show in PBI and then had to change something? Or was the UDF not working until you changed some syntax and then connected it to PBI?
My UDF runs fine when testing online and I am getting records to write to the Fabric warehouse, but again, no options show in PBI Desktop for the Button Action. I've double and triple checked my PBI Preview options and have everything enabled. Plus. when I follow all the tutorials I've found online, I see that my Button Action options when I select Data Function are completely different than the examples. I'm wondering if this is a versioning issue.
- Mauro898 months agoSuper User
SamSantos in my case the UDF showed up in Desktop but was not executing properly when used. That was due to syntax issues, eventhough the "testing" function of the UDF was saying everything is fine configured.
- SamSantos8 months agoFrequent Visitor
I see. Thanks Mauro89, not only did I need to switch to editting the report online as grazitti_sapna mentioned, it also looks like PBI did not like me trying to pass a date through. I had to change to only Strings and Integers and then PBI to allow me to connect to the Data Function in my Function Set.
- Mauro898 months agoSuper User
Awesome if grazitti_sapna and myself brought you to the solution ππ»