power
Use the power() function to calculate the value of a number raised to the power of another number. This function is an alias for pow().
Syntax
power(<base>, <exponent>)Parameters
base
integer, float
Yes
The base number to be raised.
exponent
integer, float
Yes
The exponent to which the base is raised.
Returns
Type: float
Description: The power() function returns the numerical result of the base raised to the power of the exponent. If either input is null, the function returns null.
Usage notes
Input type: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.
Alias:
power()is functionally identical topow(). Both functions can be used interchangeably.Valid Input Range: The function accepts any numeric values for both base and exponent, including negative numbers and zero.
Null Handling: If either input expression is
null, the function returnsnull.Special Cases:
power(x, 0)returns1.0for any non-zerox.power(0, 0)returns1.0.power(0, n)returns0.0forn > 0.Negative Base: When the base is negative and the exponent is not an integer, the result may be
NaN.Common Use Cases: This function is typically used within the
alterstage for exponential calculations, area/volume computations, and scientific formulas.
Examples
Example 1: Calculate power of literal values
Goal: Calculate specific power operations to verify known mathematical results.
XQL code:
Explanation: power(2, 10) returns 1024 (2^10), power(3, 3) returns 27 (3^3), and power(10, -2) returns 0.01 (10^-2 = 1/100).
Output:
1024
27
0.01
Example 2: Square field values using power
Goal: Calculate the square of values stored in a dataset field.
XQL code:
Explanation: This query squares each value in the duration_seconds field using power() with an exponent of 2. For example, 1.5 squared is 2.25.
Output:
101
1.5
2.25
102
0.8
0.64
103
10.2
104.04
Example 3: Calculate square root using power with fractional exponent
Goal: Demonstrate that power(x, 0.5) is equivalent to the square root.
XQL code:
Explanation: This query demonstrates that raising a number to the power of 0.5 is equivalent to taking its square root. Both power(x, 0.5) and sqrt(x) produce the same result.
Output:
101
4.0
2.0
2.0
102
9.0
3.0
3.0
103
16.0
4.0
4.0
Related articles
Functions:
pow(),sqrt(),exp(),multiply()Datasets:
xdr_data
Last updated
Was this helpful?
