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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

LINESTX - not able to see the intercept and slope values

Hello, 

I have started learning how to use the LINESTX fx and Dynamic filtering.

I have a small table with 'Index', 'Gender', Event', 'Y' ( 'dependent variable' ) and 'x1' - 'x4' (independent variables). At the bottom I have added a snippet of the table I am working with.

I would like that when using the event and/or gender slicers, the correct values (i.e slope and intercept) is calculated.  

The measure I am using is: 

PREDICTION =
    VAR line = LINESTX (
            ALLSELECTED ('LinearRegression'[X1]), --to keep slicers 
             [Total_Y], --Expression for Y axis
             'LinearRegression'[X1] ---Expression for X axis
            )
    VAR slope = SELECTCOLUMNS(line, [Slope1])
    VAR intercept = SELECTCOLUMNS(line, [Intercept])
    VAR x = SELECTEDVALUE('LinearRegression'[X1])
    VAR y = x * slope + intercept
    RETURN y
 
This measure seems to give me a dynamic value so I am assuming is working, however, I would like to see the value calculated for Slope1 and Intercept, and here is where my issue is. When I 'isolate' the measure that is supposed to get me these values it just doesn't work. The 'isolated'measure I mean is :
 
SlopeIntercept = LINESTX (
            ALLSELECTED ('LinearRegression'[X1]),
             [Total_Y],
             'LinearRegression'[X1]
            )
 
The error message I keep getting is The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value. Same happens when I try to use the LINEST  fx (LINEST ([column Y], [column x]) and use the column 'y' instead of the measure [Total_Y].
The data types in Power BI seem all to be correct. I am definitely missing something.
 
Any help/feedback with this is much appreciated.
 
IndexGenderEventYX1X2X3X4
0FemaleA118.3228.0558.0129.9688.45
1FemaleB119.3428.2858.4530.1789.18
2FemaleC120.1728.5159.0630.5589.77
3FemaleD120.9128.3558.9530.690.02
4FemaleE124.6929.2660.5631.392.81
5FemaleA57.4327.14 30.29 
6FemaleB57.4426.48 30.96 
7MaleC60.9928.59 32.4 
8MaleD61.1529.2 31.95 
9FemaleE61.1128.29 32.82 
10FemaleA61.6730.12 31.55 
11FemaleB59.8629.12 30.74 
12MaleC121.9227.5159.231.6990.98
13MaleD117.3526.0755.6529.5885.87
14FemaleE139.9129.6465.0135.37106.91
15FemaleA13730.465.2134.81104.42
16FemaleB134.5230.0865.2335.15102.99
17FemaleC134.4528.9864.0335.05103.35

 

 
1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

LINESTX returns a table. A measure has to be a scalar (a single) value. That's why you're getting the error.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks both for your help. I knew I was missing something - LINESTX returning a table!

I can see all values now.

FlipFlop1
Advocate I
Advocate I

SlopeIntercept =
VAR line =  LINESTX (LinearRegression,
             LinearRegression[Y],
             'LinearRegression'[X1]
            )

VAR Inter =  SELECTCOLUMNS (line, [Slope1])
RETURN
Inter
 
If you run the query in DAX query editor you can see that it is returning multiple columns.
The initial DAX query query does isolate the slope here, so that's why it works: VAR slope = SELECTCOLUMNS(line, [Slope1])

DEFINE
VAR line =  LINESTX (LinearRegression,
             LinearRegression[Y],
             'LinearRegression'[X1]
            )

VAR Inter =  SELECTCOLUMNS (line, [Slope1])
EVALUATE
line
HotChilli
Super User
Super User

LINESTX returns a table. A measure has to be a scalar (a single) value. That's why you're getting the error.

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.