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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Proquation
Frequent Visitor

Confusion with Linear Regression (DAX)

Hi there,

 

I have a railway dataset for prices per day.

 

I'm having some trouble with understanding simple linear regression using DAX. I understand the formula being used and I've tried to implement it:

Proquation_0-1715958322350.png

Proquation_1-1715959978193.png

Here's what I get when I plot the Price vs. Date as well as the Regression Line. As you can see, it is not a straight line as simple linear regression should be.

 

Another issue is that it takes the sum of prices per day instead of the average, which is what I want to predict the average prices per day. 

 

How can I fix this issue?

 

I've attached the pbix file below:

railway_data.pbix 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You can do this manually with those formulas, but I'd recommend LINESTX instead.

 

Either way, you need to aggregate by date before doing your regression.

VAR _Data_ =
    SUMMARIZE (
        ALLSELECTED ( railway ),
        railway[Date of Purchase],
        "@SumPrice", SUM ( railway[Price] )
    )
VAR _Regression_ =
    LINESTX ( _Data_, [@SumPrice], railway[Date of Purchase] )
VAR _Slope     = SELECTCOLUMNS ( _Regression_, [Slope1] )
VAR _Intercept = SELECTCOLUMNS ( _Regression_, [Intercept] )
VAR _Date      = MAX ( railway[Date of Purchase] )
VAR _Result =
    IF ( NOT ISEMPTY ( railway ), _Date * _Slope + _Intercept )
RETURN
    _Result

AlexisOlson_0-1715962891451.png

 

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

You can do this manually with those formulas, but I'd recommend LINESTX instead.

 

Either way, you need to aggregate by date before doing your regression.

VAR _Data_ =
    SUMMARIZE (
        ALLSELECTED ( railway ),
        railway[Date of Purchase],
        "@SumPrice", SUM ( railway[Price] )
    )
VAR _Regression_ =
    LINESTX ( _Data_, [@SumPrice], railway[Date of Purchase] )
VAR _Slope     = SELECTCOLUMNS ( _Regression_, [Slope1] )
VAR _Intercept = SELECTCOLUMNS ( _Regression_, [Intercept] )
VAR _Date      = MAX ( railway[Date of Purchase] )
VAR _Result =
    IF ( NOT ISEMPTY ( railway ), _Date * _Slope + _Intercept )
RETURN
    _Result

AlexisOlson_0-1715962891451.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors