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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
punksterz626
Helper II
Helper II

Remove top 20 percent and Average Out remaining result

Happy Monday everyone!

 

I would like to know how to write a measure to remove the top 20% of data from a given column and then use the Average function for the remaining value. There will be blank cells that I want to exclude.

 

See Example below: There are total of 22 rows, 2 of which has no value (blank). I want to remove the top 20% from the 20 rows with values, in this case, 50 and 49, then calculate the average for the remaining rows which should be 16.83 for the remaining 18 rows. 

 

ProjectValue
A50
B49
C48
R40
P35
Q32
O30
T22
N20
M16
D15
E10
G6
S6
F5
I5
K5
H4
J2
L2
U 
V 
8 REPLIES 8
v-yangliu-msft
Community Support
Community Support

Hi  @punksterz626 ,

Here are the steps you can follow:

1. Create calculated column.

the top 20% =
COUNTROWS('Table') * 0.2
ranx =
var _count=COUNTX(FILTER(ALL('Table'),'Table'[Value]=BLANK()),[Project])
return
IF(
    [Value]=BLANK(),BLANK(),RANKX(ALL('Table'),'Table'[Value],,DESC,Skip)+_count)

vyangliumsft_0-1648087523304.png

2. Create measure.

Avg =
AVERAGEX(FILTER(ALL('Table'),'Table'[ranx]>[the top 20%]),[Value])
Flag =
IF(
    MAX('Table'[ranx])>MAX('Table'[the top 20%]),1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1648087523304.png

4. Result:

vyangliumsft_2-1648087523307.png

 

Best Regards,

Liu Yang

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

That you sir I will review the suggested measures and report back.

VahidDM
Super User
Super User

Hi @punksterz626 

 

Try this measure:

Average Out 20% = 
VAR _2Top =
    TOPN ( 2, FILTER ( 'Table', [Value] <> BLANK () ), 'Table'[Value], DESC )
VAR _Not_Blank =
    FILTER ( 'Table', [Value] <> BLANK () )
VAR _Ex =
    EXCEPT ( _Not_Blank, _2Top )
RETURN
    AVERAGEX ( _Ex, [Value] )

 

output:

VahidDM_0-1647900952196.png

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hello,

 

Is it possible to further develop this measure to remove top 20% and bottom 20% and then do average on the rest of values?

what does this VAR means? It looks like top 2 number? What if my dataset is larger? The one provided is just a sample for simplicity. 

VAR _2Top =
    TOPN ( 2, FILTER ( 'Table', [Value] <> BLANK () ), 'Table'[Value], DESC )

  

Hi @punksterz626 

 

If you want to remove top 20% then in your main question you need to remove 4 top items (20%*20), but you mentioned 2 top items (can you please clear this)

 

for calculating the top 20% number, try this:

 

Average Out 20% = 
Var _20PerNo = 
    ROUND( COUNTROWS( FILTER ( 'Table', [Value] <> BLANK () ))*0.2 , 0 )
VAR _2Top =
    TOPN ( _20PerNo, FILTER ( 'Table', [Value] <> BLANK () ), 'Table'[Value], DESC )
VAR _Not_Blank =
    FILTER ( 'Table', [Value] <> BLANK () )
VAR _Ex =
    EXCEPT ( _Not_Blank, _2Top )
RETURN
    AVERAGEX ( _Ex, [Value] )

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

@VahidDM 

 

The measure works; however, while playing with the formula I realized there are two additional columns that can alter this formula which i forgot to include. Although i can put a filter on the visual to achieve the final result, I was wondering if it is possible to include it in the measure.

AB_Date =Blank
Status =COMP

 

The result should be 13.43 (after removing top 20% on value column)

ProjectValueAB_DateStatus
A50 COMP
B49 COMP
C48 COMP
R40 COMP
P35 COMP
Q32 COMP
O30 COMP
T22 COMP
N20 COMP
M16 COMP
D15 COMP
E10 COMP
G6 COMP
S6 COMP
F5 COMP
I5 COMP
K5 COMP
H4 COMP
J2 COMP
L2 COMP
U 1/21/2022NOTCOM
V11/23/2022OUT

 

 

 

Apparently, my math is just as bad as my DAX. You are correct, should be top 4. I will review the suggested measures and report back. Thank you so very much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.