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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Average of the last 10 values excluding the blank values on random dates inbetween

So im really having a hard time with making an average of the last 10 values excluding the blanks. the average must take into consideration that the blanks inbetween the values are inconsistent. I hope you get the picture.  I used the command below but it only copied the values instead of averaging them:

 

Average_Last_10_CZV_Values =
VAR AllDates_CZV =
ADDCOLUMNS (
VALUES ( 'afvalwater CPL'[Datum] ),
"@CZV", CALCULATE ( SUM ( 'afvalwater CPL'[CZV mg/l] ) )
) // get rid of any dates that don't have a element type amount
VAR Remove_BlankCZV =
FILTER ( AllDates_CZV, [@CZV] <> BLANK () ) // get the 10 most recent dates
VAR MostRecentDates =
TOPN ( 10, Remove_BlankCZV, 'afvalwater CPL'[Datum], DESC ) // add'em up
VAR Result =
AVERAGEX ( MostRecentDates, [@CZV] )
RETURN
Result

 

Minakami_0-1654000459576.png


Before, I used to edit the formula bar each week in Excel to update the values so it would only average the last 10 values like this:

Minakami_1-1654000570231.png

 

 

If anyone could help out that would be great!

 

thank you

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like the attached file.

 

Untitled.png

 

Last 10 CZV avg measure: =
VAR newtable =
    TOPN (
        10,
        FILTER ( ALL ( Data ), NOT ISBLANK ( Data[CZV] ) ),
        Data[Date], DESC
    )
RETURN
    IF (
        SELECTEDVALUE ( Data[Date] ) >= MINX ( newtable, Data[Date] )
            && SELECTEDVALUE ( Data[Date] ) <= MAXX ( newtable, Data[Date] )
            && NOT ISBLANK ( [CZV total measure:] ),
        AVERAGEX ( newtable, Data[CZV] )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

Try replacing VALUES ( 'afvalwater CPL'[Datum] ) with ALLSELECTED ( 'afvalwater CPL'[Datum] )

Anonymous
Not applicable

This didnt work. gave me duplicate values instead. thank you tho!

Minakami_0-1654008409060.png

 

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like the attached file.

 

Untitled.png

 

Last 10 CZV avg measure: =
VAR newtable =
    TOPN (
        10,
        FILTER ( ALL ( Data ), NOT ISBLANK ( Data[CZV] ) ),
        Data[Date], DESC
    )
RETURN
    IF (
        SELECTEDVALUE ( Data[Date] ) >= MINX ( newtable, Data[Date] )
            && SELECTEDVALUE ( Data[Date] ) <= MAXX ( newtable, Data[Date] )
            && NOT ISBLANK ( [CZV total measure:] ),
        AVERAGEX ( newtable, Data[CZV] )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thanks a bunch! this worked for me.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.