Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Liner Regression in DAX query and EXCEL Linest

Hi,

 

I've used the dax code to do liner regression in DAX outlined here

https://xxlbi.com/blog/simple-linear-regression-in-dax/

 

Simple linear regression =
VAR Known =
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED ( Table[Column] ),
            "Known[X]", [Measure X],
            "Known[Y]", [Measure Y]
        ),
        AND (
            NOT ( ISBLANK ( Known[X] ) ),
            NOT ( ISBLANK ( Known[Y] ) )
        )
    )
VAR Count_Items =
    COUNTROWS ( Known )
VAR Sum_X =
    SUMX ( Known, Known[X] )
VAR Sum_X2 =
    SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y =
    SUMX ( Known, Known[Y] )
VAR Sum_XY =
    SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X =
    AVERAGEX ( Known, Known[X] )
VAR Average_Y =
    AVERAGEX ( Known, Known[Y] )
VAR Slope =
    DIVIDE (
        Count_Items * Sum_XY - Sum_X * Sum_Y,
        Count_Items * Sum_X2 - Sum_X ^ 2
    )
VAR Intercept =
    Average_Y - Slope * Average_X
RETURN
    Intercept + Slope * [Measure X]

 

However in the EXCEL fucntion LINEST, you can add some options to get back x, x^2 and x^3. What i'm trying to do is get this values back Linest x, linest x^2 and linest x^3. I can get the known x and y, its the bit in the linest function that does the ^{1,2,3}. Linest x is the same as the slope as i think what happens is

 

y = mx + mx^2 + mx^3 + b

 

m is the slope, b is the intercept or 1

 

 

YX ResultValue EXCEL Formula
9183 Linest-0.237507232LINEST(A2:A15,B2:B15)
6843 Slope-0.237507232SLOPE(A2:A15,B2:B15)
1998 Intercept69.48525377INTERCEPT(A2:A15,B2:B15)
9853    
5197 Linest x-0.237507232LINEST(A2:A15,B2:B15^{1})
4086 Linest x2-0.016413092LINEST(A2:A15,B2:B15^{1,2})
8777 Linest x30.000180521LINEST(A2:A15,B2:B15^{1,2,3})
1174    
5420    
3712    
6928    
3148    
9131    
2787    

 

I've tried updating the DAX to do the y = mx + mx^2 + mx^3 + b but not getting the same results, any help or suggestions???

1 REPLY 1
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

It seems you may check the variable Known for your scenario. Below are some posts for your reference.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Simple-Linear-Regression/td-p/247439

https://community.powerbi.com/t5/Desktop/Deming-Linear-Regression-with-DAX/td-p/9550

https://community.powerbi.com/t5/Desktop/DAX-to-create-a-Trend-line/td-p/398438

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors