Power Query Number.Acos: Step-by-Step Guide
In this article
Number.Acos is a Power Query M function that returns the arccosine of a number, in radians, for any value between -1 and 1. To use it, open the Power Query Editor, create a new custom column or step, and call Number.Acos([YourColumn]). The result is an angle in radians; multiply by 180/PI() to convert to degrees. Nothing needs to be installed first beyond a current version of Excel, Power BI Desktop, or another tool that hosts Power Query.
What You'll Need
- A tool that includes the Power Query Editor: Excel (via Data > Get Data), Power BI Desktop (via Home > Transform data), or Power Query Online.
- A table or column of numeric values already loaded into the Power Query Editor.
- Values in the range -1 to 1 for the column you intend to pass to Number.Acos. If your data is outside that range, you will need to clamp or filter it first.
- Basic familiarity with the Power Query Editor ribbon and the formula bar. Menu labels can differ slightly by version, device, or region.
Step-by-Step
- Load your data into Power Query. In Excel, select your table and choose Data > Get Data > From Table/Range. In Power BI Desktop, choose Home > Transform data to open the editor, then load the table you want to work with. The exact path may vary slightly by version.
- Check the column type. Select the column header that holds the values you want to transform. On the Home tab, confirm the data type is a number (Decimal Number or Whole Number). If it is set to Text, use Transform > Data Type > Decimal Number before continuing.
- Add a custom column. Go to Add Column > Custom Column. Give the new column a name such as "Acos Radians".
- Enter the formula. In the Custom Column formula box, type
Number.Acos([YourColumnName]), replacing YourColumnName with the exact header of your numeric column. The column name is case-sensitive in M and must be wrapped in square brackets. - Confirm and inspect. Click OK. Power Query adds the new column. Scroll through the preview to confirm the results look like angles between 0 and about 3.14159 (π).
- Convert to degrees if needed. If you want degrees rather than radians, add another custom column with
Number.Acos([YourColumnName]) * 180 / Number.PI(). Number.PI() returns the value of π, so the result is the angle in degrees. - Handle errors before loading. If any row shows Error, the source value is likely outside -1 to 1 or is null. Use the filter dropdown on the new column to remove errors, or wrap the formula in
try ... otherwise null, for exampletry Number.Acos([YourColumnName]) otherwise null. - Set the data type on the new column. Select the new column header and set it to Decimal Number so downstream tools treat it as numeric.
- Load the result. Choose Home > Close & Load (Excel) or Home > Close & Apply (Power BI Desktop) to send the transformed table back to your workbook or model.
Common Mistakes
- Passing values outside -1 to 1. Arccosine is only defined on that interval. Values like 1.2 or -3 will produce an error, not a number.
- Forgetting the square brackets. Writing
Number.Acos(MyColumn)instead ofNumber.Acos([MyColumn])causes a syntax or name error because M treats the bare word as an identifier, not a column reference. - Using the wrong column name. Column names in M are case-sensitive and must match the header exactly, including spaces. If the header is "Cos Value", write
[Cos Value]. - Assuming the output is in degrees. Number.Acos always returns radians. Many people compare the result to a calculator set to degrees and think the function is wrong.
- Leaving the column as Text. If the source column is typed as text, the function may error or behave unexpectedly. Set the type to a number first.
- Ignoring nulls. A null input returns null, which is usually fine, but it can break later calculations that assume every row has a value.
Tips
- Use
Number.PI()rather than a hard-coded 3.14159 when converting to degrees, so you keep full precision. - Name your custom columns clearly, such as "Acos Radians" and "Acos Degrees", so the unit is obvious to anyone reading the query later.
- If you need to clamp values into the valid range, a formula like
Number.Acos(Number.Max(-1, Number.Min(1, [YourColumn])))keeps the query from failing on slightly out-of-range data. - Wrap the call in
try ... otherwisewhen the source data is messy, so one bad row does not stop the whole load. - Remember that arccosine returns the principal value between 0 and π; if your use case needs a different branch of the angle, you will have to adjust the result yourself.
Troubleshooting
If the custom column shows Error on every row, check the formula first: the function name must be spelled Number.Acos with a capital N and A, and the column reference must be in square brackets. If only some rows error, inspect those source values; anything outside -1 to 1 or any text value will fail. If the column does not appear at all, confirm you clicked OK in the Custom Column dialog and that the step was not deleted in the Applied Steps list.
If the result looks wrong, verify the input column is actually the cosine value you intended and not, for example, an angle in degrees. A common mix-up is feeding an angle into Number.Acos instead of a cosine. If the numbers are tiny or huge, check whether you expected degrees and got radians.
If the query is slow, the issue is rarely Number.Acos itself; it is a simple scalar function. Look at earlier steps such as merges or expansions. If the error persists after fixing the formula, remove the custom column, re-add it, and reload the preview. As a last resort, close and reopen the Power Query Editor, then refresh the query.
Frequently Asked Questions
What does Number.Acos return?
It returns the arccosine of a number in radians, in the range 0 to π, for inputs between -1 and 1.
How do I get the result in degrees?
Multiply the result by 180 and divide by Number.PI(), for example Number.Acos([Value]) * 180 / Number.PI().
Why do I get an error for some rows?
Those input values are probably outside -1 to 1, null, or typed as text. Filter them out, clamp them, or wrap the formula in try ... otherwise null.
Is Number.Acos available in Excel and Power BI?
Yes, it is part of the M language used by the Power Query Editor in both Excel and Power BI Desktop, and in Power Query Online. Exact menu labels can vary by version.
Can I use Number.Acos on a whole column at once?
Yes. In a custom column, the formula runs row by row, so Number.Acos([Column]) applies to every row automatically.
What is the difference between Number.Acos and Number.Cos?
Number.Cos returns the cosine of an angle; Number.Acos does the reverse and returns the angle whose cosine is the given value.