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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rqh
Frequent Visitor

Linear Regression with Date Hierarchy on X Axis

Hi everyone!

I have a line chart with average shipping costs (SC/O) as my y-axis and Calendar Quarter / Month Name as my x-axis.

[Calendar Quarter] and [Month Name] are a part of a date hierarchy created from my 'Date' table.

I have managed to create a line regression measure LINESTX using the [Order Date] column on my 'Orders' fact table. My problem with it is the line chart is becomes too granular (plots out every single date an order is placed). I would like the date to be rolled up, like by month or quarter.

I can't seem to get LINESTX to function properly when using the date hierarchy instead. Any tips?
Date tableDate tableOrders table (fact)Orders table (fact)The linear regression measure works but it doesn't when I use my date hierarchyThe linear regression measure works but it doesn't when I use my date hierarchyDAX for linear regression (thanks SQLBI)DAX for linear regression (thanks SQLBI)

 

 

3 REPLIES 3
OwenAuger
Super User
Super User

Hi @rqh 

If you are happy to visualize the results of original daily linear regression at any level of the 'Date' hierarchy, you could leave the measure unchanged except for the variable x which you could redefine as follows, depending on which date you want to select from the date range corresponding to each data point:

 

VAR x = MAX ( 'Date'[Date] )
-- or --
VAR x = AVERAGE ( 'Date'[Date] )
-- or --
VAR X = MIN ( 'Date'[Date] )

 

 As long as you use columns of the 'Date'table on the x-axis of the visual, this should work fine.

 

Does something like the above work?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
rqh
Frequent Visitor

Hi Owen,

I think we're getting close! By using your suggestions I am able to use my date hierarchy. The problem now is that, the linear regression line itself is drifting too high on the graph. By intuition. anyone can tell that the line is not the best fit line.

If you want more screenshots (or if you want my .pbix file, my dataset is fake), let me know. Thanks!Screenshot 2024-07-20 153122.pngThis is my LINESTX table, the measure Linear Regression uses the column outputs from this table.This is my LINESTX table, the measure Linear Regression uses the column outputs from this table.The new measure, per your suggestionThe new measure, per your suggestion

Thanks for the update @rqh  🙂

The PBIX would be useful if you can share it (OneDrive link or similar).

 

I do want to make sure the calcs are working as I think they are.

 

One question: Would you be happy if the regression line recalculates depending on the granularity of the axis, in order to fit the datapoints displayed?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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