Daily DAX : Day 228 TANH

 The TANH function in Power BI DAX (Data Analysis Expressions) calculates the hyperbolic tangent of a given number. It returns a value between -1 and 1, representing the ratio of the hyperbolic sine to the hyperbolic cosine of the input value. The hyperbolic tangent function is commonly used in mathematical and statistical computations, particularly in scenarios involving exponential growth, normalization, or certain types of data transformations.

Syntax

dax


TANH(number)


    number: The input value (a numeric expression) for which the hyperbolic tangent is calculated. This can be a column, constant, or expression that evaluates to a number.


Return Value


    A number between -1 and 1, representing the hyperbolic tangent of the input.


Mathematical Background

The hyperbolic tangent function is defined as:

\text{tanh}(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{e^x - e^{-x}}{e^x + e^{-x}}


Where:


    \sinh(x)

     is the hyperbolic sine.

    \cosh(x)

     is the hyperbolic cosine.

    (e) is the base of the natural logarithm.


The TANH function produces an S-shaped (sigmoid-like) curve, which makes it useful for certain types of data transformations.

Use Cases

The TANH function is less common in typical business intelligence scenarios but has specific applications in advanced analytics, such as:


    Normalization of Data:

        TANH is used to scale numerical data into a range between -1 and 1, which is helpful in preparing data for machine learning models or statistical analysis. For example, it can normalize values in a column to ensure consistent ranges for comparison.

    Modeling Non-Linear Relationships:

        In scenarios where data exhibits non-linear patterns (e.g., exponential growth or decay), TANH can transform the data into a bounded range, making it easier to model or visualize.

    Neural Networks and Machine Learning:

        TANH is often used as an activation function in neural networks because it maps inputs to a range of -1 to 1, which can help in training models by centering the data around zero. In Power BI, you might use TANH to preprocess data before feeding it into a predictive model.

    Financial or Scientific Calculations:

        In finance or physics, TANH may appear in formulas related to growth rates, risk modeling, or physical simulations where hyperbolic functions are relevant.


Example in Power BI DAX

Suppose you have a table SalesData with a column GrowthRate containing numerical values, and you want to apply the TANH function to normalize these values.

DAX Expression

dax


NormalizedGrowth = TANH(SalesData[GrowthRate])


    Scenario: The GrowthRate column contains values like 0.5, 1.2, -0.8, etc.

    Result: The NormalizedGrowth column will contain values between -1 and 1, such as:

        TANH(0.5) ≈ 0.462

        TANH(1.2) ≈ 0.833

        TANH(-0.8) ≈ -0.664


You can use this new column in visuals or calculations to analyze normalized growth trends.

Practical Example

Imagine you're analyzing customer satisfaction scores ranging from -5 to 5, and you want to normalize them for a machine learning model. You create a calculated column:

dax


NormalizedScore = TANH(CustomerData[SatisfactionScore])


This transforms the scores into a range of -1 to 1, which can be used in further calculations or as input for a predictive model integrated with Power BI.

Notes


    Behavior with Extreme Values: For very large positive or negative inputs, TANH approaches 1 or -1, respectively, due to its asymptotic nature.

    Comparison with Other Functions: TANH is similar to the sigmoid function but is centered around zero, making it preferable in cases where negative values are meaningful.

    Performance: The TANH function is computationally lightweight, but ensure the input values are valid numbers to avoid errors.


Limitations


    TANH is not commonly used in standard business reporting (e.g., sales, revenue tracking), so its use is typically limited to specialized analytical tasks.

    If the input is non-numeric or blank, the function may return an error or unexpected results, so data cleansing is important.



Comments

Popular posts from this blog

Daily DAX : Day 65 INFO.TABLEPERMISSIONS

Daily DAX : Day 55 PV