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 C(n, k)
The function comb_fl() is a user-defined function (UDF) that calculates C(n, k), the number of combinations for selection of k items out of n, without order. It's based on the native gamma() function to calculate factorial. For more information, see facorial_fl(). For a selection of k items with order, use perm_fl().
Syntax
comb_fl(n, k)
Learn more about syntax conventions.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| n | int, long, or real | ✔️ | The total number of items. |
| k | int, long, or real | ✔️ | 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 comb_fl(), see Example.
let comb_fl=(n:int, k:int)
{
let fact_n = gamma(n+1);
let fact_nk = gamma(n-k+1);
let fact_k = gamma(k+1);
tolong(fact_n/fact_nk/fact_k)
};
// Write your query to use the function here.
Example
To use a query-defined function, invoke it after the embedded function definition.
let comb_fl=(n:int, k:int)
{
let fact_n = gamma(n+1);
let fact_nk = gamma(n-k+1);
let fact_k = gamma(k+1);
tolong(fact_n/fact_nk/fact_k)
};
range n from 3 to 10 step 3
| extend k = n-2
| extend cnk = comb_fl(n, k)
Output
| n | k | cnk |
|---|---|---|
| 3 | 1 | 3 |
| 6 | 4 | 15 |
| 9 | 7 | 36 |