Search code examples
powerbissasdax

Record Exclusion Measure Not Working in Matrix Visual


I am working on a measure that is essentially just taking a sum over paid values associated with some sequence ids that fall within a predefined range but I am having trouble trying to resolve an issue when I use the measure in a matrix visual.

The measure is outlined below:

Filtered Paid :=
VAR Selection =
    SELECTEDVALUE ( 'Selection'[ID], 1 )
VAR ThreeSigma =
    3 * STDEV.P ( Data[PAID] )
VAR SeqMean =
    AVERAGE ( Data[PAID] )
VAR ExcludedSeqs =
    CALCULATETABLE (
        VALUES ( Data[SequenceId] ),
        KEEPFILTERS (
            FILTER (
                ALL ( Data[PAID] ),
                Data[PAID] < SeqMean + ThreeSigma
                    && Data[PAID] > SeqMean - ThreeSigma
            )
        )
    )
RETURN
    SWITCH (
        Selection,
        3, CALCULATE ( SUM ( Data[PAID] ), ExcludedSeqs ),
        CALCULATE ( SUM ( Data[PAID] ) )
    )

The measure works just fine when I use it in a card or a map but when I try using it in a matrix visual as the 'Values' field with the Data[SequenceId] as the 'Rows' field the measure never renders any values it just spins forever. I've tried using a few different variations of this measure and all seem to give me the same issue. I've also tried a visual level filter to exclude those records but I can't seem to get it down.

Any help would be appreciated!

Thanks!!


Solution

  • I ended up finding a solution using a visual level filter:

    Visual Level Filter :=
    VAR Selection =
        SELECTEDVALUE ( 'Selection'[ID], 1 )
    VAR ThreeSigma =
        CALCULATE ( 3 * STDEV.P ( Data[PAID] ), ALL ( Data[SequenceId] ) )
    VAR SeqMean =
        CALCULATE ( AVERAGE ( Data[PAID] ), ALL ( Data[SequenceId] ) )
    VAR Total =
        SUM ( Data[PAID] )
    RETURN
        SWITCH (
            Selection,
            3, IF ( AND ( Total < SeqMean + ThreeSigma, Total > SeqMean - ThreeSigma ), 1, 0 ),
            1
        )
    

    Basically I just set it equal to 1 as a visual level filter and use a calculate(sum(data[paid])) on the matrix. It works but if anyone has a more elegant solution that may be performant I am all ears.