Forum Discussion

gooranga1's avatar
gooranga1
Power Participant
7 years ago
Solved

Percentile.exc Error

I have a calculation;     Percentile 95 = if(ISERROR(PERCENTILE.exc(FactDoorOpenTimes[SecondsOpen],0.95)),BLANK(),PERCENTILE.exc(FactDoorOpenTimes[SecondsOpen],0.95)) That calculates the 95 perce...
  • OwenAuger's avatar
    OwenAuger
    7 years ago

    gooranga1 

     

    If you have n values, PERCENTILE.EXC treats the minimum value as having percentile rank 1/(n+1) and the maximum value as having percentile rank n/(n+1). For example, if you have 9 values, the lowest allowable percentile rank is 1/(9+1)=0.1 and the highest is 9/(9+1)=0.9.

     

    PERCENTILE.INC, on the other hand, treats the minimum value as having percentile rank 0 and the maximum value has having percentile rank 1.

     

    I see from your reply that you've switched to PERCENTILE.INC, which can handle any percentile rank value from 0 to 1.

     

    If you did want to stick with PERCENTILE.EXC, you can do this but unfortunately IFERROR or IF ( ISERROR (...) ) aren't good enough to safeguard against the error in this case. It appears Power BI can't handle evaluating an invalid percentile even if it is simply used to test for an error value.

     

    Instead, you can test whether the percentile rank (k = 0.95 in your case) is within the allowable range before calling the PERCENTILE.EXC function, which avoids PERCENTILE.EXC being calculated when not valid.

     

    This measure should do the trick (a few variables used for clarity):

     

    Percentile 95 a =
    VAR k = 0.95
    // Both COUNT and PERCENTILEX.EXC ignore blanks
    VAR NumValues = COUNT ( FactDoorOpenTimes[SecondsOpen] ) VAR LowerBound = 1 / ( NumValues + 1 ) VAR UpperBound = NumValues / ( NumValues + 1 ) RETURN IF ( AND ( k >= LowerBound, k <= UpperBound ), PERCENTILE.EXC ( FactDoorOpenTimes[SecondsOpen], k) )

    Regards,

     

    Owen