Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Switch services using the Version drop-down list. Learn more about navigation.
Applies to: ✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel
Calculate P(n, k)
The function perm_fl() is a user-defined function (UDF) that calculates P(n, k), the number of permutations for selection of k items out of n, with order. It's based on the native gamma() function to calculate factorial, (see facorial_fl()). For selection of k items without order, use comb_fl().
Syntax
perm_fl(n, k)
Learn more about syntax conventions.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| n | int |
✔️ | The total number of items. |
| k | int |
✔️ | The selected number of items. |
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:
Define the function using the following let statement. No permissions are required.
Important
A let statement can't run on its own. It must be followed by a tabular expression statement. To run a working example of perm_fl(), see Example.
let perm_fl=(n:int, k:int)
{
let fact_n = gamma(n+1);
let fact_nk = gamma(n-k+1);
tolong(fact_n/fact_nk)
};
// Write your query to use the function here.
Example
To use a query-defined function, invoke it after the embedded function definition.
let perm_fl=(n:int, k:int)
{
let fact_n = gamma(n+1);
let fact_nk = gamma(n-k+1);
tolong(fact_n/fact_nk)
}
;
range n from 3 to 10 step 3
| extend k = n-2
| extend pnk = perm_fl(n, k)
Output
| n | k | pnk |
|---|---|---|
| 3 | 1 | 3 |
| 6 | 4 | 360 |
| 9 | 7 | 181440 |