factorial_fl()
This article describes factorial_fl() user-defined function.
Calculate factorial.
The function factorial_fl() is a UDF (user-defined function) that calculates factorial of positive integers (n!). It’s a simple wrapper of the native gamma() function.
Syntax
factorial_fl(n)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| n | int | ✔️ | The input integer for which to calculate the factorial. |
Function definition
You can define the function by either embedding its code as a query-defined function, or creating it as a stored function in your database, as follows:
Query-defined
Define the function using the following let statement. No permissions are required.
let factorial_fl=(n:int)
{
gamma(n+1)
};
// Write your query to use the function here.
Stored
Define the stored function once using the following .create function. Database User permissions are required.
.create-or-alter function with (folder = "Packages\\Stats", docstring = "Calculate factorial")
factorial_fl(n:int)
{
gamma(n+1)
}
Example
Query-defined
let factorial_fl=(n:int)
{
gamma(n+1)
};
range x from 1 to 10 step 3
| extend fx = factorial_fl(x)
Stored
range x from 1 to 10 step 3
| extend fx = factorial_fl(x)
Output
| x | fx |
|---|---|
| 1 | 1 |
| 4 | 24 |
| 7 | 5040 |
| 10 | 3628799 |
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.