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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
jwc
New Member

Using LINESTX with NEW TABLE works, but fails in function for NEW MEASURE

I reviewed an number of posts and videos on how to do linear regression.

 

I can get a regression of "vbat vs ts" to work when i create a new TABLE using the following;

 

Regression = LINESTX('LowPower', [vbat], [ts])

 

And then create a new MEASURE "vbat_lr" using;

 

vbat_lr =
var _m = SELECTCOLUMNS(Regression, [Slope1])
var _b = SELECTCOLUMNS(Regression, [Intercept])
var x = SELECTEDVALUE(LowPower[ts])
var y = _b + _m * x
RETURN y

 

However, other tutorials suggest not using a regression table and embedding the LINESTX function in the MEASURE;

 

vbat_lr =
var _reg = LINESTX('LowPower', [vbat], [ts])
var _m = SELECTCOLUMNS(_reg, [Slope1])
var _b = SELECTCOLUMNS(_reg, [Intercept])
var x = SELECTEDVALUE(LowPower[ts])
var y = _b + _m * x
RETURN y

 

This doesnt work!

My vbat_lr measure gives identical values to vbat (suggesting that _lr has Slope1=1 and Intercept=0)

I would prefer not having an extra table and getting the second method working.
I very new to PowerBI.
Hopefully somebody can see what I am doing wrong with embedding the LINESTX in the measure.

1 REPLY 1
lbendlin
Super User
Super User

SELECTCOLUMNS  will produce a list. You normally need to convert that into a scalar value. In your case the table produced by LINESTX is already a single row table, so your approach may work.

 

Do you have some sample data points from the LowPower table?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

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