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
Minakami
Frequent Visitor

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.


Go to My LinkedIn Page


View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

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

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.


Go to My LinkedIn Page


Thanks a bunch! this worked for me.

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.

Top Solution Authors