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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
LoicIDCC
Regular Visitor

Extract End of Year Values of a linear regression.

Dear community,

I calculate a linear regression of a measure ( CumulativePATT_ID ) using the values of a certain number of previous months from a calendar table 'CALENDAR'[Year_Month] (Year_Month = date(year('CALENDAR'[Date]),MONTH('CALENDAR'[Date]),1)))

LoicIDCC_1-1626117392327.png

 

I want to create a new table by year, that extracts the end-of-year value of the regression (with the same slope and intercept).

How do I do that?

Thanks!

 

LoicIDCC_0-1626117375077.png

 

Regression by Year and Month = VAR Known = FILTER ( SELECTCOLUMNS ( FILTER(ALL('CALENDAR'[Year_Month]),'CALENDAR'[Year_Month]<=TODAY()), "Known[X]", 'CALENDAR'[Year_Month], "Known[Y]", [CumulativePATT_ID] ), 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 SUMX ( DISTINCT ( 'CALENDAR'[Year_Month]), Intercept + Slope * 'CALENDAR'[Year_Month] )

 

1 ACCEPTED SOLUTION

Hi @LoicIDCC ,

 

Try the following formula:

 

Table = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('CALENDAR'[Date].[Year]),
        DISTINCT(Data[Category])
    ),
    "Running Total", CALCULATE(
            DISTINCTCOUNT(Data[Unique_ID]),
            FILTER(
                ALL('Data'),
                Data[Category] = EARLIER([Category])
                && 'Data'[Date] <= DATE( EARLIER([Year]), 12, 31 )
            )
        )
)

vkkfmsft_0-1626334906719.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@LoicIDCC Right, so as part of your linear regression you know the slope (m) and y intercept, correct? So just plug that back into the formula for slope. x2 is the number of months after your y intercept or whatever y value you want to start with. y2 is your unknown but everything else should be known in that formula, correct?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@LoicIDCC I have an example of this in my book, DAX Cookbook. It is recipe 8 in Chapter 12. You can get the PBIX here: gdeckler/DAXCookbook (github.com)

 

But, if you know the slope and y-intercept, then the formula is m = (y2 - y1) / (x2 - x1) so you would want to solve that equation for y2, or y2 = m(x2 - x1) + y1. If you use y1 as your y intercept, x1 would be 0 so y2 = m * x2 + y1.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Sorry but I still don't understand.

Here is my file with some dummy data.: Report link 

I need the second chart by year, with the EOY value for each year.

 

 

Hi @LoicIDCC ,

 

Try the following formula:

 

Table = 
ADDCOLUMNS(
    CROSSJOIN(
        DISTINCT('CALENDAR'[Date].[Year]),
        DISTINCT(Data[Category])
    ),
    "Running Total", CALCULATE(
            DISTINCTCOUNT(Data[Unique_ID]),
            FILTER(
                ALL('Data'),
                Data[Category] = EARLIER([Category])
                && 'Data'[Date] <= DATE( EARLIER([Year]), 12, 31 )
            )
        )
)

vkkfmsft_0-1626334906719.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

Thanks for your example but I don't have a problem with the linear regression itself.

My linear regression is calculated by month. 

I want to create a measure by year, that is a filtered table of the linear regression by month, with the value at the end of each year.

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.