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
bengisby
Helper I
Helper I

average of Top n percent per month

Goal: average seconds of only the lowest 80% of seconds

Based on data:

IDyy-mmNameseconds

1

21-03Ben30
221-03Joe40
321-03Ben10
421-03Joe20
521-03Joe30
621-04Joe40
721-04Joe30
821-04Ben240
921-04Ben12
1021-04Ben15

 

Desired Output:

Table Visualization:

yy-mmtop 80% Average
21-0322.5
21-0424.25

 

Note: 21-03 is ignoring ID 2 and 21-04 is ignoring ID 8 because they are not in the lowest 80%.

 

Ideally, the measure could work under the name column as well. E.g.

NameTop 80% Average
Ben16.75
Joe30

 

2 ACCEPTED SOLUTIONS
v-jingzhang
Community Support
Community Support

Hi @bengisby 

Please use the following measures.

top 80% Average by yy-mm =
VAR _yymm = SELECTEDVALUE ( 'Table 1'[yy-mm] )
VAR _80number = COUNTROWS ( FILTER ( ALL ( 'Table 1' ), 'Table 1'[yy-mm] = _yymm ) ) * 0.8
VAR _80table =
    FILTER (
        'Table 1',
        RANKX (
            FILTER ( ALL ( 'Table 1' ), 'Table 1'[yy-mm] = _yymm ),
            CALCULATE ( SUM ( 'Table 1'[seconds] ) ),
            ,
            ASC
        ) <= _80number
    )
RETURN
    AVERAGEX ( _80table, 'Table 1'[seconds] )
top 80% Average by name =
VAR _name = SELECTEDVALUE ( 'Table 1'[Name] )
VAR _80number = COUNTROWS ( FILTER ( ALL ( 'Table 1' ), 'Table 1'[Name] = _name ) ) * 0.8
VAR _80table =
    FILTER (
        'Table 1',
        RANKX (
            FILTER ( ALL ( 'Table 1' ), 'Table 1'[Name] = _name ),
            CALCULATE ( SUM ( 'Table 1'[seconds] ) ),
            ,
            ASC
        ) <= _80number
    )
RETURN
    AVERAGEX ( _80table, 'Table 1'[seconds] )
top 80% Average =
IF (
    ISFILTERED ( 'Table 1'[yy-mm] ),
    [top 80% Average by yy-mm],
    IF ( ISFILTERED ( 'Table 1'[Name] ), [top 80% Average by name] )
)

031602.jpg

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-jingzhang
Community Support
Community Support

Hi @bengisby 

Please use the following measures.

top 80% Average by yy-mm =
VAR _yymm = SELECTEDVALUE ( 'Table 1'[yy-mm] )
VAR _80number = COUNTROWS ( FILTER ( ALL ( 'Table 1' ), 'Table 1'[yy-mm] = _yymm ) ) * 0.8
VAR _80table =
    FILTER (
        'Table 1',
        RANKX (
            FILTER ( ALL ( 'Table 1' ), 'Table 1'[yy-mm] = _yymm ),
            CALCULATE ( SUM ( 'Table 1'[seconds] ) ),
            ,
            ASC
        ) <= _80number
    )
RETURN
    AVERAGEX ( _80table, 'Table 1'[seconds] )
top 80% Average by name =
VAR _name = SELECTEDVALUE ( 'Table 1'[Name] )
VAR _80number = COUNTROWS ( FILTER ( ALL ( 'Table 1' ), 'Table 1'[Name] = _name ) ) * 0.8
VAR _80table =
    FILTER (
        'Table 1',
        RANKX (
            FILTER ( ALL ( 'Table 1' ), 'Table 1'[Name] = _name ),
            CALCULATE ( SUM ( 'Table 1'[seconds] ) ),
            ,
            ASC
        ) <= _80number
    )
RETURN
    AVERAGEX ( _80table, 'Table 1'[seconds] )
top 80% Average =
IF (
    ISFILTERED ( 'Table 1'[yy-mm] ),
    [top 80% Average by yy-mm],
    IF ( ISFILTERED ( 'Table 1'[Name] ), [top 80% Average by name] )
)

031602.jpg

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

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.