Forum Discussion

SamSantos's avatar
SamSantos
Frequent Visitor
8 months ago
Solved

Data function Button for running User Defined Function (UDF) is not configurable

I have created a User Defined Function button to writeback date from Power BI to a Fabric Warehouse. The UDF works when testing online and writes to the table and returns a string, but in PBI Desktop I cannot get the button to connect. I have all the preview items enabled that the documentation tells me to enable, and I've followed all the online documentation I could find, but my options still do not look like the options in online articles and other community posts.

When I select the fx options, it opens up a menu and I can select my UDF set or the specific UDF, but nothing changes and the button tooltip still says "The data function is not properly configured". What am I missing or doing wrong?

 

  • 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!

  • SamSantos's avatar
    SamSantos
    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. 

11 Replies

  • 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!

    • SamSantos's avatar
      SamSantos
      Frequent Visitor

      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

    • SamSantos's avatar
      SamSantos
      Frequent Visitor

      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.

       

       

      • Mauro89's avatar
        Mauro89
        Super 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.

    • SamSantos's avatar
      SamSantos
      Frequent Visitor

      I did select Import but it didn't seem to do anything. The Button options I get are completely different than the linked video, i.e. no "Workspace", "Function Set", nor "Data Function" drop downs, only the (fx) button. Per grazitti_sapna response, it may just be due a recent change / rollout?

      • kushanNa's avatar
        kushanNa
        Super User

        Hi SamSantos 

         

        Yes there's a change in the properties from the tutorial , but everything works fine for me in the desktop , DB is getting updated as well