Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Number.Cosh Function: Usage and Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Number.Cosh function in Power Query (M language) calculates the hyperbolic cosine of a given number. To use it, you simply wrap your numeric value or column reference inside the function, such as Number.Cosh([ColumnName]), which returns the result of (e^x + e^-x) / 2. This is primarily used in advanced engineering, physics, or financial modeling where catenary curves or specific growth decay patterns are analyzed.

What You'll Need

  • Microsoft Excel (with Power Query installed) or Power BI Desktop.
  • A dataset containing a numeric column to serve as the input for the hyperbolic cosine calculation.
  • Access to the Power Query Editor (via Data > Get Data or Transform Data).

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data > Launch Power Query Editor. In Power BI, click Transform Data on the Home ribbon.
  2. Select Your Table: From the Queries pane on the left, select the table that contains the numerical data you wish to transform.
  3. Add a Custom Column: Navigate to the Add Column tab on the top ribbon. Click on Custom Column. This opens the Custom Column dialog box where you can write your M formula.
  4. Enter the Formula: In the Custom column formula box, type the following: Number.Cosh([YourColumnName]). Replace [YourColumnName] by double-clicking the desired column from the Available columns list on the right side of the dialog.
  5. Name the Column: In the New column name field, give your column a descriptive name, such as "Hyperbolic Cosine Result".
  6. Verify the Data Type: Once the column is created, you will notice the data type is likely set to "Any". Click the icon to the left of the column header and select Decimal Number to ensure the output is treated as a numeric value for further calculations.
  7. Apply Changes: Click File > Close & Apply (Power BI) or Home > Close & Load (Excel) to bring the calculated data into your spreadsheet or data model.

Common Mistakes

One of the most frequent errors is attempting to use Number.Cosh on a column that is not explicitly typed as a number. If your column is set to "Text", Power Query will return an Expression.Error stating that the function cannot convert the value to a number. Always ensure your source column is set to Decimal Number or Whole Number before adding the custom column.

Another common mistake is case sensitivity. The M language is strictly case-sensitive. Writing number.cosh or Number.COSH will result in an " identifier not found" error. You must use the exact casing: Number.Cosh.

Users also occasionally confuse the hyperbolic cosine (cosh) with the standard trigonometric cosine (cos). While Number.Cos calculates the cosine of an angle (in radians), Number.Cosh calculates the hyperbolic cosine. Using the wrong function will lead to mathematically incorrect results that may not be immediately obvious if the input values are very small.

Tips

If you are working with very large numbers, be aware that Number.Cosh grows exponentially. This can lead to "Infinity" results if the input value exceeds the maximum capacity of a 64-bit floating-point number. If you encounter this, consider normalizing your data or applying a logarithmic transformation before calculating the hyperbolic cosine.

For those who prefer not to create a new column, you can use the "Transform" feature. Instead of going to the Add Column tab, go to the Transform tab, select your column, and use a custom function via the formula bar. This replaces the original values with the cosh results, saving space in your data model.

When documenting your Power Query steps, it is helpful to add a description to the step in the Applied Steps pane. Right-click the "Added Custom" step, select Properties, and note that this step calculates the hyperbolic cosine for specific engineering requirements. This makes the query maintainable for other users.

Troubleshooting

If you see Error in every cell of your new column, the first step is to click in the white space next to the word "Error" to read the specific error message at the bottom of the screen. If it says "We cannot convert the value... to type Number", go back to the previous step in the Applied Steps list and change the type of your input column to Decimal Number.

If the formula is accepted but the results seem wildly incorrect, check your input units. Number.Cosh expects a real number. If you are attempting to use it as part of a trigonometric identity involving angles, ensure you aren't actually looking for Number.Cos.

If Power Query becomes slow or unresponsive after adding this function to a table with millions of rows, try to perform the calculation as late as possible in your query sequence. Filter out unnecessary rows first to reduce the number of calculations the engine must perform.

In cases where the result is Infinity, check for outliers in your source data. A single extremely high value in the input column can cause the Number.Cosh function to hit the floating-point limit. Use a filter or a conditional column to cap the input values before passing them to the function.

Frequently Asked Questions

What is the mathematical difference between Cos and Cosh?

Number.Cos is a circular trigonometric function based on a circle, while Number.Cosh is a hyperbolic function based on a hyperbola. Cosine oscillates between -1 and 1, whereas Hyperbolic Cosine starts at 1 and increases toward infinity as the input moves away from zero.

Can I use Number.Cosh in a Power BI DAX measure?

No, Number.Cosh is an M language function used in the Power Query Editor. If you need the hyperbolic cosine in a DAX measure, you must use the DAX equivalent COSH(). While they perform the same math, the syntax and the engine that processes them are different.

Does Number.Cosh support negative numbers?

Yes, it does. Because the hyperbolic cosine is an even function, Number.Cosh(x) is equal to Number.Cosh(-x). The result will always be greater than or equal to 1 regardless of whether the input is positive or negative.

Why is my result showing as a very long decimal?

The Number.Cosh function returns a double-precision floating-point number. To make the data more readable, you can use the "Round" feature in the Transform tab or wrap your formula in Number.Round(Number.Cosh([Column]), 2) to limit the decimal places.

Is there a way to calculate Cosh without using the built-in function?

Yes, you can manually recreate the formula using Number.Exp. The formula would be (Number.Exp([Column]) + Number.Exp(-[Column])) / 2. This will yield the exact same result as the Number.Cosh function.