Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Outliers in DAX

Hi, I'm working on a dataset that has 2 (or more) months worth of data. We mark the outliers manually in Excel by sorting the resolution hrs and then getting 5% of the total rows per month and then marking the bottom and top 5% with "Outlier" and the middle values with "Normal". In the final measure, we want the value to exclude all those marked with "Outlier" in a monthly basis. 

 

I need a calculated column that will do this for me in PowerBI so that when I use the slicer for month, the marking for Outlier and Normal will automatically change as well. 

 

Do you have any suggestions? Here's the sample data set. 

 

IDRestored HoursMonth RestoredOutlier Flag
C-0010.012021-05Outlier
C-0121.1288783432021-05Outlier
C-0151.2014204982021-05Normal
C-0101.2491101172021-05Normal
C-0161.3004064082021-05Normal
C-0091.4278883192021-05Normal
C-0111.6230734332021-05Normal
C-0131.6429827132021-05Normal
C-0081.7080778482021-05Normal
C-0141.8032076682021-05Normal
C-0061.813980352021-05Normal
C-0071.966169622021-05Normal
C-00232021-05Normal
C-0175.0897301672021-05Normal
C-0195.2567098852021-05Normal
C-0225.3100292022021-05Normal
C-0245.3150798532021-05Normal
C-0185.4692671532021-05Normal
C-0235.5873053292021-05Normal
C-0215.7423168622021-05Normal
C-0205.9939406092021-05Normal
C-003512021-05Normal
C-0052122021-05Outlier
C-00457752021-05Outlier
C-0463.0430738782021-06Outlier
C-0423.186849552021-06Outlier
C-0433.6052380512021-06Normal
C-0443.6853298032021-06Normal
C-0453.9505394662021-06Normal
C-0384.3540582262021-06Normal
C-0414.6488599572021-06Normal
C-0404.6673963482021-06Normal
C-0374.8742793532021-06Normal
C-0394.9727515752021-06Normal
C-0275.042435552021-06Normal
C-0265.3849489042021-06Normal
C-0255.4397205672021-06Normal
C-0285.9724869352021-06Normal
C-0496.0747145732021-06Normal
C-0506.4715259932021-06Normal
C-0486.679320562021-06Normal
C-0476.8531024932021-06Normal
C-03511.23757772021-06Normal
C-02911.336805212021-06Normal
C-03011.390725332021-06Normal
C-03611.393329492021-06Normal
C-03111.628650162021-06Normal
C-03411.669616072021-06Normal
C-03211.830122772021-06Outlier
C-03311.92019542021-06Outlier

 

Thanks!

 

  • Hi Anonymous ,

     

    Try to create a new column like below:

    outlier_test = 
    var rank_asc = RANKX(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]),'Table'[Restored Hours],,ASC,Dense)
    var rank_desc = RANKX(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]),'Table'[Restored Hours],,DESC,Dense)
    var count_row = COUNTROWS(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]))*0.05
    return IF(rank_asc<=count_row||rank_desc<=count_row,"Outlier","Normal")

     


    Best Regards,
    Liang
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • V-lianl-msft's avatar
    V-lianl-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    Try to create a new column like below:

    outlier_test = 
    var rank_asc = RANKX(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]),'Table'[Restored Hours],,ASC,Dense)
    var rank_desc = RANKX(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]),'Table'[Restored Hours],,DESC,Dense)
    var count_row = COUNTROWS(FILTER('Table',EARLIER('Table'[Month Restored])='Table'[Month Restored]))*0.05
    return IF(rank_asc<=count_row||rank_desc<=count_row,"Outlier","Normal")

     


    Best Regards,
    Liang
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for this! Worked like a charm. 🙂

  • "I need a calculated column that will do this for me in PowerBI so that when I use the slicer for month, the marking for Outlier and Normal will automatically change as well. "

     

    Calculated columns do not care about user interactions or slicers. Did you mean to say you need a measure?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Ah, essentially, on my sample, the column Outlier should be changing and recalculated to show outlier and normal depending on the month that the user will select. 

    Sorry, just getting back into pbi and i'm a bit lost.