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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
NishPatel
Resolver II
Resolver II

Last 5 Average Measure

I have below data. And New Part No is added (Incremental and Unique) with new cost and Part type. I am looking for a measure that will give me average cost of last 5 part no. by part type.

 

Part No.CostPart Type
1000116Part A
1000219Part A
1000324Part A
1000425Part A
1000522Part A
1000627Part A
1000726Part A
1000822Part A
1000929Part A
1001017Part A
10001105Part B
1000280Part B
10003114Part B
10004112Part B
1000595Part B
10006160Part B
1000789Part B
1000858Part B
1000951Part B
1001088Part B
1000111056Part C
100023992Part C
100033718Part C
100044337Part C
100054078Part C
100061174Part C
100079540Part C
100084646Part C
100095113Part C
1001011466Part C

 

Measure that I am looking for will give me below result.

Part TypeLast 5 Avg
Part A24.20
Part B89.20
Part C6387.80

 

 

Thank You in Advance

 

Nish

 

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @NishPatel ,

 

Please check the formula:

Last_5_avg =
CALCULATE (
    AVERAGE ( 'Table'[Cost] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Part Type] = SELECTEDVALUE ( 'Table'[Part Type] )
            && 'Table'[Part No.] <= MAX ( 'Table'[Part No.] )
            && 'Table'[Part No.]
                > MAX ( 'Table'[Part No.] ) - 5
    )
)

vjaywmsft_0-1657099691936.png

 

Best Regards,

Jay

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

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @NishPatel ,

 

Please check the formula:

Last_5_avg =
CALCULATE (
    AVERAGE ( 'Table'[Cost] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Part Type] = SELECTEDVALUE ( 'Table'[Part Type] )
            && 'Table'[Part No.] <= MAX ( 'Table'[Part No.] )
            && 'Table'[Part No.]
                > MAX ( 'Table'[Part No.] ) - 5
    )
)

vjaywmsft_0-1657099691936.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@NishPatel , Try like

 

Create a rank column first
Rank = rankx(filter(Table, [Part Type] = earlier([Part Type])), [Part No.],,desc, dense)

 

then create a measure
AvergaeX(Filter(Table, Table[Rank]<=5), Table[Cost])

Rank is working perfectly. However, It's giving me 5 different averages by part no and not by part type. I am looking for an average cost of last 5 part nos for each part type. From my table above, Last 5 Actuals for Part A are 27,26,22,29 and 17 so Average should be 24.2. But I am getting 5 different Average's for last 5 Part nos. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.