Forum Discussion

bvy's avatar
bvy
Helper V
3 years ago

Fun with the new LINEST / LINESTX DAX Functions...

I love these functions and hope to leverage them to get the slope of a best fit line over a series of data. My data table looks like this: 

 

Table1

DateTimeTypeReading
Feb 3 12PMSpeed100
Feb 5 9PMSpeed80
Feb 7 8PMTemp45

Etc. 

 

Now I can write this DAX function to give me the slope (and other stats) of the best fit line for Speed. 

 

 

SELECTCOLUMNS(LINESTX(FILTER(Table1, Table1[Type] = "Speed"), Table1[Reading], Table1[DateTime]), "Slope", [Slope1])​

 

 

Okay, first of all, that returns a table with a single rown and single column, but it's still a table. How can I convert that to a scalar value without resorting to variables? 

 

Second, and more importantly, do you see an easy way for me to get slope values for EVERY Type (Speed. Temperature, etc.) without having to hard code each one in its own measure?  

 

Thanks. 

3 Replies