AlexisOlson's avatar
AlexisOlson
Super User
3 years ago
Status:
Accepted

Filter context issues with LINESTX

I've been trying to incorporate LINESTX into my reporting but keep running into errors when modifying the filter context.

 

To create a minimal reproducible example, I've loaded a data table like this:

and defined a measure as follows:

 

LINEST_Intercept = 
VAR Summary =
    ADDCOLUMNS (
        VALUES ( Data[ID] ),
        "@Y",  CALCULATE ( SUM ( Data[Y]  ) ),
        "@X1", CALCULATE ( SUM ( Data[X1] ) ),
        "@X2", CALCULATE ( SUM ( Data[X2] ) )
    )
VAR Coeffs = LINESTX ( Summary, [@Y], [@X1], [@X2] )
VAR Intercept = SELECTCOLUMNS ( Coeffs, "Intercept", [Intercept] )
RETURN
    Intercept

 

This works fine initially in a matrix like this:

However, if I add a slicer on ID and make any selection other than the full range, I get an error on the entire visual.

 

Error Message:
MdxScript(Model) (4, 1) Calculation error in measure 'Data'[LINEST_Intercept]:
A table of multiple values was supplied where a single value was expected.

 

If I try using MAXX instead of SELECTCOLUMNS inside my measure

 

VAR Intercept = MAXX ( Coeffs, [Intercept] )

 

and filter the ID, I either get "An unexpected exception occurred" or weird results with a blank Group like this:

 

None of this weirdness happens if I use a different function that returns a single row like TOPN ( 1, ... ).

 

Please see the attached sample file.

 

Tagging a few people for awareness. Please ignore if you aren't interested.

jeroenterheerdtmarcorussoGreg_DecklerValtteriNCNENFRNLtamerj1wdx223_Danielsmpa01 

18 Comments