Forum Discussion

Sharmilshah's avatar
Sharmilshah
Frequent Visitor
1 year ago
Solved

Write Back data from PowerBI to SharePoint

Hi all,
I'm working on a Power BI report where users need to update a SharePoint list by clicking a Power Automate button. I have everything working when values are selected from slicers or table visuals (like Request ID, Status, etc.).
However, I'm stuck on how to let the user enter free text input (like a comment) and pass that into the Power Automate flow.


⚙️ Setup so far:

  1. Power BI visual has fields: RequestID, Status (from slicer)
  2. Power Automate visual is configured and updates SharePoint successfully when using predefined values
  3. No Power Apps is being used — I want to keep everything inside Power BI

🧩 Problem:

  • There's no native free text input in Power BI
  • I can't figure out how to let the user type a custom comment and pass it to the flow
  • Tried using slicers or prebuilt tables, but they only support static values

Is there any workaround or clean way to collect user-entered text (like a comment) inside Power BI and pass it dynamically into a Power Automate flow?
Appreciate any help or best practices!
Thanks!

  • vojtechsima's avatar
    vojtechsima
    1 year ago

    hey, Sharmilshah ,

    You can still use user defined function, you just need to call graph api with delegated access to sharepoint list.

     

    However, you essentially need a registered app with permission to access SharePoint's Graph API to share with the sites you need. Should be delegated per site, it can look like this:

    Depends on your admins, but they can grant you this.

     

    And once you have this, you can call graph's rest api for SharePoint, I don't have code at end, but I vibe coded something like this (please note, it can be wrong, just an idea):

    import fabric.functions as fn
    import logging
    import requests
    
    udf = fn.UserDataFunctions()
    
    @udf.connection(argName="sharepoint", alias="mysharepoint")
    @udf.function()
    def UpdateSharePointComment(
        sharepoint: fn.FabricGenericConnection,  # Use the right connection type for your setup
        site_url: str,
        list_name: str,
        item_id: int,
        comment: str,
        access_token: str  # Ideally, get this securely or use Managed Identity if possible
    ) -> str:
        logging.info("Processing UpdateSharePointComment")
    
        # Validation
        if not comment or not comment.strip():
            raise fn.UserThrownError("Comment cannot be empty.")
    
        # Compose SharePoint API URL
        url = f"{site_url}/_api/web/lists/getbytitle('{list_name}')/items({item_id})"
    
        headers = {
            "Authorization": f"Bearer {access_token}",
            "Accept": "application/json;odata=verbose",
            "Content-Type": "application/json"
        }
    
        # SharePoint expects a PATCH for updates
        data = {
            "__metadata": {"type": "SP.Data.YourListNameListItem"},  # You must specify the internal list item type
            "Comment": comment  # Change to your column's internal name
        }
    
        # PATCH request
        response = requests.post(
            url,
            headers=headers,
            json=data,
            params={"$select": "Id"}
        )
    
        if response.status_code not in (200, 204):
            raise fn.UserThrownError(f"SharePoint update failed: {response.text}")
    
        return f"SharePoint item {item_id} updated with comment '{comment}'."
    



  • Hi Sharmilshah ,

    Thanks for posting in Microsoft Fabric Community.

    Just checking in to see if have you had a chance to review the information provided by vojtechsima.

    As mentioned, since you're using a workspace with Fabric capacity, you're in a good position to take advantage of the Text Slicer (preview). This allows users to enter free text directly in Power BI, which can then be passed into a User-Defined Function and used within a Translytical Task Flow to update the SharePoint list.

     

    The blog shared earlier by vojtechsima walks through how to set up native writeback using Fabric, which is relevant for your scenario.

    Also as suggested, to write back directly to a SharePoint list, you can use the Graph API. This does require registering an app with the necessary delegated permissions to access the SharePoint site, but once configured, it allows you to update list items, including custom fields like comments.

     

    Please reach out for further assistance.

     

    Also thanks speedramps for suggesting Power Apps and providing helpful resources. This helps others with similar requirement.

     

    Regards.

     

     

     

     

8 Replies

    • Sharmilshah's avatar
      Sharmilshah
      Frequent Visitor

      Thank you vojtechsima  for sharing the TTF option. Your details are excellent. In my use case, I have a sharepoint list as a datasource. I can pull data into Fabric (as I have workspace with Fabric capacity) but my intention is not to just write back to Fabric but want to update end source which is SharePoint list also. I tried to figure out a solution but couldn't find a direct way.

      • vojtechsima's avatar
        vojtechsima
        Super User

        hey, Sharmilshah ,

        You can still use user defined function, you just need to call graph api with delegated access to sharepoint list.

         

        However, you essentially need a registered app with permission to access SharePoint's Graph API to share with the sites you need. Should be delegated per site, it can look like this:

        Depends on your admins, but they can grant you this.

         

        And once you have this, you can call graph's rest api for SharePoint, I don't have code at end, but I vibe coded something like this (please note, it can be wrong, just an idea):

        import fabric.functions as fn
        import logging
        import requests
        
        udf = fn.UserDataFunctions()
        
        @udf.connection(argName="sharepoint", alias="mysharepoint")
        @udf.function()
        def UpdateSharePointComment(
            sharepoint: fn.FabricGenericConnection,  # Use the right connection type for your setup
            site_url: str,
            list_name: str,
            item_id: int,
            comment: str,
            access_token: str  # Ideally, get this securely or use Managed Identity if possible
        ) -> str:
            logging.info("Processing UpdateSharePointComment")
        
            # Validation
            if not comment or not comment.strip():
                raise fn.UserThrownError("Comment cannot be empty.")
        
            # Compose SharePoint API URL
            url = f"{site_url}/_api/web/lists/getbytitle('{list_name}')/items({item_id})"
        
            headers = {
                "Authorization": f"Bearer {access_token}",
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json"
            }
        
            # SharePoint expects a PATCH for updates
            data = {
                "__metadata": {"type": "SP.Data.YourListNameListItem"},  # You must specify the internal list item type
                "Comment": comment  # Change to your column's internal name
            }
        
            # PATCH request
            response = requests.post(
                url,
                headers=headers,
                json=data,
                params={"$select": "Id"}
            )
        
            if response.status_code not in (200, 204):
                raise fn.UserThrownError(f"SharePoint update failed: {response.text}")
        
            return f"SharePoint item {item_id} updated with comment '{comment}'."
        



  • Consider usiing a Power App visual inside Power BI

    learn how for free here

     

    Please click thumbs up because I have tried to help.

    Then click [accept solution] if it works.

    (It does works, I have used it lots of times and it does exactly what you want).

    However, SharePoint is anot the best choice.

    Consider using Dataverse or SQL

     

     

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Community Support

    Hi Sharmilshah ,

    Thanks for posting in Microsoft Fabric Community.

    Just checking in to see if have you had a chance to review the information provided by vojtechsima.

    As mentioned, since you're using a workspace with Fabric capacity, you're in a good position to take advantage of the Text Slicer (preview). This allows users to enter free text directly in Power BI, which can then be passed into a User-Defined Function and used within a Translytical Task Flow to update the SharePoint list.

     

    The blog shared earlier by vojtechsima walks through how to set up native writeback using Fabric, which is relevant for your scenario.

    Also as suggested, to write back directly to a SharePoint list, you can use the Graph API. This does require registering an app with the necessary delegated permissions to access the SharePoint site, but once configured, it allows you to update list items, including custom fields like comments.

     

    Please reach out for further assistance.

     

    Also thanks speedramps for suggesting Power Apps and providing helpful resources. This helps others with similar requirement.

     

    Regards.

     

     

     

     

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Community Support

    Hi Sharmilshah ,
    We wanted to kindly follow up regarding your query. If you need any further assistance, please reach out.
    Thank you.

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Community Support

    Hi Sharmilshah ,
    Just wanted to check if the responses provided were helpful. If further assistance is needed, please reach out.
    Thank you.

  • v-veshwara-msft's avatar
    v-veshwara-msft
    Community Support

    Hi Sharmilshah ,
    We wanted to kindly follow up regarding your query. If you need any further assistance, please reach out.
    Thank you.