# Optional parameter in a function

**URL:** <https://forum.kx.com/t/optional-parameter-in-a-function/14190>\
**Category:** Community Support\
**Tags:** imported, kdb-and-q\
**Created:** [April 10, 2025, 1:40pm UTC](https://forum.kx.com/t/optional-parameter-in-a-function/14190 "2025-04-10T13:40:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnzerno](https://avatars.discourse-cdn.com/v4/letter/j/5fc32e/32.png) [@Johnzerno](https://forum.kx.com/u/Johnzerno)\
**Post date:** [April 10, 2025, 1:40pm UTC](https://forum.kx.com/t/optional-parameter-in-a-function/14190/1 "2025-04-10T13:40:51Z")

</div>

[https://learninghub.kx.com/forums/topic/optional-parameter-in-a-function](https://learninghub.kx.com/forums/topic/optional-parameter-in-a-function)

Is there a way to have an optional parameter in a function, and if this parameter is not supplied the function logic will behave differently?

I would want the function to act like the below.

func:{[requiredParam;requiredParam2;optionalParam]

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logic if optionalParam is supplied

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; logic if optionalParam is not supplied}

---

<div class="post-metadata">

**Author:** ![unterrainer\_ale](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/unterrainer_ale/32/108_2.png) [@unterrainer\_ale](https://forum.kx.com/u/unterrainer_ale)\
**Post date:** [April 10, 2025, 1:44pm UTC](https://forum.kx.com/t/optional-parameter-in-a-function/14190/2 "2025-04-10T13:44:32Z")

</div>

The way you can solve this is by using a dictionary as parameter, mapping each parameter name as key to a value. You can then check if a certain parameter is in the parameter names (using key). This also allows you to pass more than 8 parameters to a function
