Smart Systems for Home

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

Power Query Number.Tan Function: How to Use It

· 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.Tan function in Power Query calculates the tangent of a given angle in radians. It is used for trigonometric calculations in data analysis, such as modeling waveforms, engineering computations, or geometric transformations. To use it, you must provide a numeric value (in radians); if your angle is in degrees, convert it first using Number.PI / 180. No additional setup is required beyond having Power Query available in Excel or Power BI.

What You'll Need

  • A dataset containing numeric values representing angles (preferably in radians, or ready for conversion)
  • Power Query Editor open in Excel (Data > Get Data > Launch Power Query Editor) or in Power BI (Home > Transform Data)
  • Basic familiarity with adding custom columns in Power Query

Step-by-Step

  1. Open your Excel workbook or Power BI report and load the dataset containing the angle values into Power Query. In Excel, go to the Data tab, click Get Data > From Other Sources > From Microsoft Query, or use an existing connection; in Power BI, click Home > Transform Data to open the Power Query Editor.
  2. In the Power Query Editor, locate the column that contains the angle values. If the angles are in degrees, you must convert them to radians first. To do this, click on the column header, then go to the Add Column tab and select Custom Column.
  3. In the Custom Column dialog, name the new column (e.g., "AngleInRadians"). In the formula box, enter: [YourColumnName] * Number.PI / 180, replacing "YourColumnName" with the actual column name (e.g., [AngleDegrees]). Click OK to create the new column.
  4. With the angle now in radians, add the tangent calculation. Click Add Column > Custom Column again. Name this new column "Tangent" (or similar).
  5. In the formula box, enter: Number.Tan([AngleInRadians]), using the exact name of the radians column you created in step 3. Click OK. This applies the tangent function row-by-row to every value in the radians column.
  6. Review the results in the new column. Values should appear as decimals (e.g., 0.577 for 30°, 1 for 45°, undefined for 90°—which will appear as Infinity or NaN depending on the input). If needed, right-click the column header and choose Remove Other Columns to keep only essential columns.
  7. Click Close & Load to load the updated table back into Excel or Power BI. In Excel, the data appears on a new worksheet; in Power BI, it appears in the model for use in visuals.

Common Mistakes

  • Using degrees directly in Number.Tan without conversion: This yields incorrect results, as the function expects radians. For example, Number.Tan(45) calculates tan(45 radians), not tan(45°).
  • Typing the function incorrectly: Power Query is case-sensitive. Use exactly "Number.Tan", not "number.tan" or "Number.TAN".
  • Passing non-numeric data: If the source column contains text (e.g., "N/A" or empty strings), the function returns an error. Ensure the column is of type Whole Number or Decimal Number before applying the function.
  • Ignoring undefined values: Tangent is undefined at 90°, 270°, etc. If your angle column includes such values, Number.Tan will return Infinity or NaN, which may break downstream visuals or calculations.
  • Forgetting to rename or reference the correct column: Using an outdated or misspelled column name in the formula (e.g., [Angle] vs. [AngleInRadians]) will cause a "Expression.Error".

Tips

  • Use the built-in error handler: Wrap the function in a try...otherwise clause to handle undefined cases gracefully. For example: try Number.Tan([AngleInRadians]) otherwise null.
  • Validate your angle column first: In Power Query, click the column header > Transform > Data Type, and ensure it is set to Decimal Number or Fixed Decimal.
  • Test with known values: Before applying to your full dataset, add a small test table with angles like 0, 30, 45, 60, 90 (converted to radians), and verify results match expected tangents (0, ~0.577, 1, ~1.732, Infinity).
  • Use formatting for readability: After loading into Excel, format the tangent column as Number with 4–6 decimal places to avoid long trailing digits.
  • Combine with conditional logic: Use if statements to cap extreme values—for example, if [Tangent] > 1000 then 1000 else [Tangent], to prevent visuals from distorting due to Infinity.

Troubleshooting

If you encounter errors when using Number.Tan, follow these checks in order:

  1. Check for non-numeric data: In Power Query, right-click the angle column > Change Type > Using Converter > Decimal Number. If conversion fails, filter out or replace non-numeric entries first (e.g., use Filter > Text Filters > Does Not Contain to exclude text rows).
  2. Verify the formula syntax: Ensure the formula uses exact capitalization: "Number.Tan([ColumnName])". Avoid spaces around parentheses or brackets. Copy-paste the column name from the column header to avoid typos.
  3. Handle Infinity or NaN: If your output shows "Infinity" or "NaN", locate the problematic rows by filtering the tangent column for errors. Then, either remove those rows (Right-click row > Remove > Remove Errors) or apply a conditional column as described in the Tips section.
  4. Confirm radians conversion: If results seem off, manually calculate one row: Take an angle in degrees (e.g., 45), multiply by 3.14159265358979 / 180 ≈ 0.785398, then compute tan(0.785398) ≈ 1. If not, your conversion formula is wrong.
  5. Restart Power Query: Occasionally, the editor may cache errors. Close Power Query, restart Excel or Power BI, and re-open the query to refresh.
  6. Update software: Ensure you are using a recent version of Excel (2016 or later) or Power BI Desktop. Older versions may lack full support for Number.Tan.

Frequently Asked Questions

What is the difference between Number.Tan and Number.Sin in Power Query?

Number.Tan calculates the tangent (opposite/adjacent ratio), while Number.Sin calculates the sine (opposite/hypotenuse ratio). Both require radians, but their outputs differ mathematically and are used for different modeling purposes.

Can I use Number.Tan with negative angles?

Yes. Tangent is an odd function, so tan(−θ) = −tan(θ). Power Query handles negative radians correctly—for example, Number.Tan(-0.785398) returns approximately -1.

Why does my tangent value show as "NaN"?

"NaN" (Not a Number) usually means the input was invalid—for example, a blank cell, text, or the result of an earlier error. Check the source column for non-numeric entries and clean them before applying Number.Tan.

Does Number.Tan work in DirectQuery mode in Power BI?

No. Number.Tan is a Power Query M function and is evaluated during data transformation (import mode). In DirectQuery, it cannot be used in the Power Query Editor; instead, compute tangent in the source database or use DAX’s TAN function in the report layer.

How precise is Number.Tan?

Power Query uses IEEE 754 double-precision floating-point arithmetic, giving approximately 15 decimal digits of precision. For most engineering and analytical use cases, this is sufficient.

Can I apply Number.Tan to multiple columns at once?

Not directly in one step. You must add a custom column for each angle column individually. However, you can use the Advanced Editor to write a custom function that loops over columns if you have programming experience with M language.