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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
PowerBIUserX
Frequent Visitor

Trend analysis using linear regression gradient per category

Hi,

 

I'm building a report and need to calculate a trend over time per category, to identify top increases/decreases over time.

The end goal is to have a trend value (gradient of linear regression) per category, to then filter on the top 10 by trend value.


I've seen the following article on linear regression, but don't know how to go about applying it per categoryhttps://community.fabric.microsoft.com/t5/Desktop/Trend-line-values/td-p/1641410

Additionally (nice to have), I would like to exclude any potential errors, for example by removing the top5%/bottom 5% of data (by value per category).

 

I appreciate any help!

 

Few comments:

  • My Value from below is actually the result of a measure
  • There are between 100-200 categories.
  • The trend value in itself is rather meaningless and just used to sort/filter on categories.

Essentially, I would like to get from:

PowerBIUserX_0-1702663864700.png


To this:

PowerBIUserX_1-1702663875594.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PowerBIUserX 

I add a month column in the table

vxinruzhumsft_1-1702973968772.png

Then modifiy the Lines measure

Lines =
VAR a =
    LINESTX (
        FILTER ( ALLSELECTED ( 'Table' ), [Category] IN VALUES ( 'Table'[Category] ) ),
        [Value_measure],
        [Month]
    )
RETURN
    MINX ( a, [Slope1] )

Output

vxinruzhumsft_0-1702973931838.png

Best Regards!

Yolo Zhu

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

4 REPLIES 4
PowerBIUserX
Frequent Visitor

Hi @Anonymous ,

Thank you for your reply. While it works on the limited dataset I initially provided, I do not think the solution works in all cases.
If I understand correctly, the measures you suggested calculate the slope [ (y2-y1)/(x2-x1) ] of the maximum point and minimum point in the dataset, but not the slope of the regression. In the dataset it works because they are already linear functions.

On the following dataset (non-linear function), the slope I am expected is -3.5%, but your measure returns -45%.

PowerBIUserX_0-1702894697539.png

Do you have an idea on how to achieve the same but with the slope of the linear regression?


Anonymous
Not applicable

Hi @PowerBIUserX 

I add a month column in the table

vxinruzhumsft_1-1702973968772.png

Then modifiy the Lines measure

Lines =
VAR a =
    LINESTX (
        FILTER ( ALLSELECTED ( 'Table' ), [Category] IN VALUES ( 'Table'[Category] ) ),
        [Value_measure],
        [Month]
    )
RETURN
    MINX ( a, [Slope1] )

Output

vxinruzhumsft_0-1702973931838.png

Best Regards!

Yolo Zhu

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

 

 

 

Works perfectly! Thank you so much 😊

Anonymous
Not applicable

Hi @PowerBIUserX 

You can refer to the following solution.

Sample data 

vxinruzhumsft_0-1702877290162.png

I create a sample measure

Value_measure = SUM('Table'[Value]) 

Then create a measure

Lines =
VAR _minxy =
    MINX (
        FILTER ( ALLSELECTED ( 'Table' ), [Category] IN VALUES ( 'Table'[Category] ) ),
        [Value_measure]
    )
VAR _maxy =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [Category] IN VALUES ( 'Table'[Category] ) ),
        [Value_measure]
    )
VAR x_minxy =
    MINX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Category]
                IN VALUES ( 'Table'[Category] )
                    && [Value_measure] = _minxy
        ),
        MONTH ( [Date] )
    )
VAR x_maxy =
    MINX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [Category]
                IN VALUES ( 'Table'[Category] )
                    && [Value_measure] = _maxy
        ),
        MONTH ( [Date] )
    )
RETURN
    DIVIDE ( _maxy - _minxy, x_maxy - x_minxy )

vxinruzhumsft_1-1702877375844.png

Best Regards!

Yolo Zhu

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

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

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.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.