Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
MangoMagic
New Contributor II

Fabric User Data Function parameter defaults?

Was trying to create a function which runs a stored proc and returns some results, is there a way to set default values in parameters, e.g. to make parameters optional and default them if no value is given?

I tried following but it doesn't seem to work, the function doesn't even publish when I try and set default values ๐Ÿ˜ž

 

@udf.connection(argName="sqlDB",alias="Control")
@udf.function()
def GetWatermark(sqlDB: fn.FabricSqlConnection, ID: int, option: str = "Get watermark", description: str = None)-> list:
    option = option.lower()
    
    if option == "get watermark":
        query = "exec exec [dbo].[Get_ETLSettings] @ID = {ID}, @Option = '{option}';"

    #if option == "hour":

    # Establish a connection to the SQL database
    connection = sqlDB.connect()
    cursor = connection.cursor()

    # Execute the query
    cursor.execute(query)

    # Fetch all results
    results = []
    for row in cursor.fetchall():
        results.append(row)

    # Close the connection
    cursor.close()
    connection.close()
        
    return results

 

1 ACCEPTED SOLUTION
v-karpurapud
Honored Contributor III

Hi @MangoMagic 

Thank you for contacting the Microsoft Fabric Community Forum.

 

Currently, Microsoft Fabric's Python User Defined Functions (UDFs) created with the @udf.function decorator do not allow default values or optional parameters in their definitions. If you try to set a default value for a parameter, such as option: str = "Get watermark", the function will not publish or compile correctly in the Fabric environment.

 

To avoid issues, make sure all parameters are explicitly defined and provided when calling the function. If you need default behavior, handle it inside the function by checking if a parameter is empty or null and then assigning a value as needed. This method works within the platform's current limitations and ensures your UDFs will run as expected.

 

from microsoft.fabric import udf

import microsoft.fabric.functions as fn



@udf.connection(argName="sqlDB", alias="Control")

@udf.function()

def GetWatermark(sqlDB: fn.FabricSqlConnection, ID: int, option: str, description: str) -> list:

   

    if not option:

        option = "get watermark"

    else:

        option = option.lower()



    if option == "get watermark":

        query = f"EXEC [dbo].[Get_ETLSettings] @ID = {ID}, @Option = '{option}';"

    else:

      

        query = f"EXEC [dbo].[Get_ETLSettings] @ID = {ID}, @Option = '{option}';"



    connection = sqlDB.connect()

    cursor = connection.cursor()



    cursor.execute(query)

    results = cursor.fetchall()



    cursor.close()

    connection.close()



    return results

 

Regards,

Karpurapu D,

Microsoft Fabric Community Support Team.

View solution in original post

4 REPLIES 4
v-karpurapud
Honored Contributor III

Hi @MangoMagic 

Thank you for contacting the Microsoft Fabric Community Forum.

 

Currently, Microsoft Fabric's Python User Defined Functions (UDFs) created with the @udf.function decorator do not allow default values or optional parameters in their definitions. If you try to set a default value for a parameter, such as option: str = "Get watermark", the function will not publish or compile correctly in the Fabric environment.

 

To avoid issues, make sure all parameters are explicitly defined and provided when calling the function. If you need default behavior, handle it inside the function by checking if a parameter is empty or null and then assigning a value as needed. This method works within the platform's current limitations and ensures your UDFs will run as expected.

 

from microsoft.fabric import udf

import microsoft.fabric.functions as fn



@udf.connection(argName="sqlDB", alias="Control")

@udf.function()

def GetWatermark(sqlDB: fn.FabricSqlConnection, ID: int, option: str, description: str) -> list:

   

    if not option:

        option = "get watermark"

    else:

        option = option.lower()



    if option == "get watermark":

        query = f"EXEC [dbo].[Get_ETLSettings] @ID = {ID}, @Option = '{option}';"

    else:

      

        query = f"EXEC [dbo].[Get_ETLSettings] @ID = {ID}, @Option = '{option}';"



    connection = sqlDB.connect()

    cursor = connection.cursor()



    cursor.execute(query)

    results = cursor.fetchall()



    cursor.close()

    connection.close()



    return results

 

Regards,

Karpurapu D,

Microsoft Fabric Community Support Team.

Thank you, that worked ๐Ÿ˜ƒ

Hi @v-karpurapud I have a similar problem. In my use case, I am using UDF into powerbi report and passing the parameters through Text slicer. If I dont pass the value from pbi report, it doesn't enabled the button hence, I need to pass the all values irrespective it is required or not. Is there a workaround for same?

v-karpurapud
Honored Contributor III

Hi @Sharmilshah 


In Microsoft Fabric, Fabric UDFs require all parameters to be explicitly provided, and the Invoke Function visual in Power BI disables the button whenever any parameter evaluates to BLANK(). Because of this behavior, optional parameters or default values in the UDF signature are currently not supported.


To work around this, keep all parameters mandatory in the UDF signature and implement any โ€œoptional/defaultโ€ logic inside the function by checking whether a parameter is empty or null and assigning a default value as needed. On the Power BI side, ensure that measures mapped to UDF parameters never return BLANK(). This can be achieved using SELECTEDVALUE() with a fallback value or COALESCE() for numeric parameters. For example, return "Get watermark" when no option is selected and "" for optional text fields instead of BLANK().

Regards,

Microsoft Fabric Community Support Team.

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (10,778)