Daily DAX : Day 437 GCD
Power BI DAX Function: GCD
The GCD (Greatest Common Divisor) function in DAX returns the largest positive integer that divides two integers without leaving a remainder. It is a mathematical function similar to Excel's GCD.
Syntax
GCD(number1, number2)
- number1, number2: Integer values (or expressions evaluating to integers). Only two arguments are supported.
Return Value
An integer representing the greatest common divisor.
Remarks & Limitations
- Returns
#VALUE!if any argument is non-numeric. - Returns
#NUM!if any argument is less than 0 or >= 2^53. - Not supported in DirectQuery mode for calculated columns or row-level security (RLS).
- The function is considered deprecated in some contexts, but still available.
Examples
| Expression | Result | Explanation |
|---|---|---|
| GCD(12, 18) | 6 | 6 divides both 12 and 18 evenly. |
| GCD(7, 13) | 1 | 7 and 13 are prime to each other. |
| GCD(48, 18) | 6 | Largest common divisor is 6. |
| GCD(5, 0) | 5 | GCD with 0 is the number itself (if positive). |
Use Cases
The GCD function is niche in business intelligence but useful in specific scenarios:
- Fractions simplification: Reduce ratios (e.g., divide numerator and denominator by GCD).
- Calculating Least Common Multiple (LCM): LCM(a, b) = ABS(a * b) / GCD(a, b).
- Scaling or grouping data: Find common factors for dimensions like sizes, quantities, or time intervals.
- Manufacturing/Inventory analysis: Optimize packaging or batch sizes based on common divisors.
- Educational or mathematical models: In reports involving number theory or algorithms.
For more than two numbers, nest the function: GCD(GCD(a, b), c).
Comments
Post a Comment