The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
05-21-2025 17:28 PM - last edited 05-23-2025 08:26 AM
With Translytical task flows you can enable datapoint annotation directly within your report.
For example, in the report below you can add, edit or delete annotations about each month’s sales data. Here we can see that to add a new data annotation, you select the datapoint, input your comment, and then submit, and it appears immediately on the report.
Data annotation scenarios may consist of up to three user data functions to:
Here is the user data function for the Add Annotation scenario:
import fabric.functions as fn
import logging
import calendar
udf = fn.UserDataFunctions()
@udf.connection(argName="sqlDB",alias="Translytical")
@udf.function()
def AddAnnotation(sqlDB: fn.FabricSqlConnection, date: str, commentdate: str, comment: str, user: str) -> str:
logging.info('Python UDF trigger function processed a request.')
# month abbr to YYYY-MM-DD
month_num = list(calendar.month_abbr).index(date)
formatted_date = f"{2023}-{month_num:02d}-10"
data = (commentdate, formatted_date, user, comment)
# Establish a connection to the SQL database
connection = sqlDB.connect()
cursor = connection.cursor()
logging.info("Adding comment ... ")
# Insert data into the table
insert_query = "INSERT INTO [dbo].[DataReasoning] ([Date_Created],[Date_Month],[User],[Comment]) VALUES (?, ?, ?, ?);"
cursor.execute(insert_query, data)
logging.info("Comment was added")
# Commit the transaction
connection.commit()
# Close the connection
cursor.close()
connection.close()
return "Comment was successfully added"
Here is the user data function for the Edit Annotation scenario:
import fabric.functions as fn
import logging
import calendar
udf = fn.UserDataFunctions()
@udf.connection(argName="sqlDB",alias="Translytical")
@udf.function()
def EditAnnotation(sqlDB: fn.FabricSqlConnection, comment: str, commentdate: str, user: str, newcomment :str ) -> str:
logging.info('Python UDF trigger function processed a request.')
data = (newcomment, commentdate, user, comment)
# Establish a connection to the SQL database
connection = sqlDB.connect()
cursor = connection.cursor()
# Insert data into the table
logging.info("Updating comment")
update_query = " UPDATE [dbo].[DataReasoning] SET [Comment] = ?, [Date_Created] = ?, [User] = ? WHERE [Comment] = ?;"
cursor.execute(update_query, data)
logging.info("Comment was updated")
# Commit the transaction
connection.commit()
# Close the connection
cursor.close()
connection.close()
return "Comment was successfully updated"
Here is the user data function for the Delete Annotation scenario:
import fabric.functions as fn
import logging
udf = fn.UserDataFunctions()
@udf.connection(argName="sqlDB",alias="Translytical")
@udf.function()
def DeleteAnnotation(sqlDB: fn.FabricSqlConnection, comment: str ) -> str:
logging.info('Python UDF trigger function processed a request.')
# Establish a connection to the SQL database
connection = sqlDB.connect()
cursor = connection.cursor()
# Delete comment
logging.info("Deleting comment ... ")
delete_query = "DELETE FROM [dbo].[DataReasoning] WHERE [Comment] = ?"
cursor.execute(delete_query,comment)
logging.info("Comment was deleted")
# Commit the transaction
connection.commit()
# Close the connection
cursor.close()
connection.close()
return "Comment was successfully deleted"
Feel free to use this code as inspiration for your data annotations scenarios!
Hi @SujataNarayana , Thanks for sharing this, it helps a lot. one question I have does this feature works for the reports present in Power BI service only? I have created a power bi report with "translytical task flows" for adding comments from the report. It was working fine in Power BI Service, but after embedding the report into a portal, the button is not responding. Does this feature works only in power bi service?