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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
mogugu_84
Helper I
Helper I

replicate Excel SLOPE calculation

Hi Community

 

I need to re-create this Excel formula calculation (Slope) in Power BI. 

So basically the known x is number from 1 to 24 represent 24 months of data, from month 12, the slope calculation is known y = the unit value in row 3 for the past 12 columns and the known x = the sequence number in row 1 for the past 12 columns

as shown in the below Excel formula bar, any idea how to calculation this figure using DAX? Thanks

mogugu_84_3-1729702048757.png

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi, Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1729856202496.png

 

 

Jihwan_Kim_0-1729856179107.png

 

 

Volume total: = 
SUM( Data[Volume] )

 

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Slope: = 
VAR _calendar =
    ALL ( 'Calendar'[Year-Month], 'Calendar'[Year-Month sort] )
VAR _window =
    WINDOW (
        -11,
        REL,
        0,
        REL,
        _calendar,
        ORDERBY ( 'Calendar'[Year-Month sort], ASC )
    )
VAR _condition =
    COUNTROWS ( FILTER ( _window, [Volume total:] <> BLANK () ) ) = 12
VAR _t =
    ADDCOLUMNS (
        _window,
        "@x", RANK ( SKIP, _calendar, ORDERBY ( 'Calendar'[Year-Month sort], ASC ) ),
        "@y", [Volume total:]
    )
VAR _linestx =
    LINESTX ( _t, [@y], [@x] )
RETURN
    IF ( _condition, MAXX ( _linestx, [Slope1] ) )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

9 REPLIES 9
Sdnf
Regular Visitor

Thanks a lot Jihwan Kim, your solution for the slope works perfectly!

Jihwan_Kim
Super User
Super User

Hi,

The image is too small for me. Even if I click the image to make it larger, it is still too small.

Could you please provide your sample pbix file's link & how the expected result looks like? And then, I can try to look into it.

Thank you.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

thank you Kim. I realise i can't upload a  file or store somewhere online with link...i have pasted the actual figures as below, if this is not handy, you can use dummy numbers as well, doesnt matter. 

 

the key desired the outcome is to create a measure in Power BI called slope and the calculation of Slope in Sep 22 should be 35.8, as the Excel forumla spit out. and Oct 22 slope should be 20.2 ....

 

i have repasted the bigger photo with what's the Excel forumla looks like

 

if you use dummy data, as long as it match same data using the Excel "Slope" formula" calculation, it would be all perfect to adapt. Thank you

 

 123456789101112131415161718192021222324    
MonthOct.21Nov.21Dec.21Jan.22Feb.22Mar.22Apr.22May.22Jun.22Jul.22Aug.22Sep.22Oct.22Nov.22Dec.22Jan.23Feb.23Mar.23Apr.23May.23Jun.23Jul.23Aug.23Sep.23    
Volume2,8283,2473,3132,7752,9123,2992,9253,1493,1933,1723,5243,4023,1143,3733,5603,0323,1643,3843,2273,7193,3233,5783,6693,490    

 

mogugu_84_0-1729847951005.png

mogugu_84_1-1729848009856.png

 

 

 

Hi, Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1729856202496.png

 

 

Jihwan_Kim_0-1729856179107.png

 

 

Volume total: = 
SUM( Data[Volume] )

 

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

 

Slope: = 
VAR _calendar =
    ALL ( 'Calendar'[Year-Month], 'Calendar'[Year-Month sort] )
VAR _window =
    WINDOW (
        -11,
        REL,
        0,
        REL,
        _calendar,
        ORDERBY ( 'Calendar'[Year-Month sort], ASC )
    )
VAR _condition =
    COUNTROWS ( FILTER ( _window, [Volume total:] <> BLANK () ) ) = 12
VAR _t =
    ADDCOLUMNS (
        _window,
        "@x", RANK ( SKIP, _calendar, ORDERBY ( 'Calendar'[Year-Month sort], ASC ) ),
        "@y", [Volume total:]
    )
VAR _linestx =
    LINESTX ( _t, [@y], [@x] )
RETURN
    IF ( _condition, MAXX ( _linestx, [Slope1] ) )

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Thanks for this solution Jihwan it works perfectly but I found an issue when the volume data is = 0 in any month included in the 12 previous, slope is not calculated. Look this snapshot: Maybe DAX slope formula needs some adjustements to avoid this issue?

Sdnf_0-1730718833986.png

 

Hi,

please try to change the below part, something like,

 

XXXXX

 

VAR _condition =
    COUNTROWS ( FILTER ( _window, [Volume total:] <> BLANK () ) ) = 12

 

 

 

OOOOO

 

VAR _condition =
    COUNTROWS ( FILTER ( _window, NOT([Volume total:] == BLANK ()) ) ) = 12

 

In current measure, the condition checks the blank value, including zero.

In the fixed measure, the condition checks the real blank value, excluding zero.

 

Please check whether this works.

Thank you.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Thanks Jihwan but I'm afraid this solution doesn't work, now the slope figures are wrong and includes also months without volume figures despite those months are not selected in the months filter:

Sdnf_0-1730813577969.pngSdnf_1-1730813641995.png

 

Jihwan_Kim
Super User
Super User

Hi,

Please try to use LINESTX DAX function.

 

LINESTX function (DAX) - DAX | Microsoft Learn

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Hi,

I'd also need exactly how to recreate this slope formula in power BI, could you please write the complete DAX formula for this request?:

 

 I need to re-create this Excel formula calculation (Slope) in Power BI. 

So basically the known x is number from 1 to 24 represent 24 months of data, from month 12, the slope calculation is known y = the unit value in row 3 for the past 12 columns and the known x = the sequence number in row 1 for the past 12 columns

as shown in the below Excel formula bar, any idea how to calculation this figure using DAX? Thanks

Sdnf_0-1729841169227.png

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.