Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

LINESTX return 0 for slope

Strange situation. Using the XXL BI Dax measure for Linerar regression.

X= are dates

Y = numbers

 

The table is filtered with a slicer. Looking at the returned columns for different categories, I get a variety of intercept values., but every slope is 0.

 

Thoughts?

 

 

Simple linear regression =
VAR Known =
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED (Report_Usage[datetime] ),
            "Known[X]", Report_Usage[datetime],
            "Known[Y]", Report_Usage[Views]
        ),
        AND (
            NOT ( ISBLANK ( Known[X] ) ),
            NOT ( ISBLANK ( Known[Y] ) )
        )
    )
VAR SlopeIntercept =
    LINESTX(Known, Known[Y], Known[X])
VAR Slope =
    SELECTCOLUMNS(SlopeIntercept, [Slope1])
VAR Intercept =
    SELECTCOLUMNS(SlopeIntercept, [Intercept])
RETURN Slope

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    There could be several possible reasons for this issue, such as:

    - The data points in your table are not linearly related, meaning that there is no correlation between the x and y values. This could happen if the data is random, constant, or has outliers that distort the trend.

    - The data points in your table have a very small variation in the x or y values, meaning that the slope is very close to zero but not exactly zero. Adjust the format of your measure to display more decimal places. 

     

    You can refer to the following posts that may be helpful to you:

    Implementing linear regression in Power BI - SQLBI

    powerbi - Power BI Linear Regression DAX measure always returns 0 for slope - Stack Overflow

    Simple Linear Regression with DAX - Microsoft Fabric Community

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Well, the data is report usage data. Dates, Number of views, so not random.

    Maybe I'm not seting up the DAX correctly?