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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
ranbeermakin
Resolver III
Resolver III

DAX Help: Find last 5 nonblank values in a column

Hi All,

 

I require help in getting AVG of the last 5 nonblank values from column B. My table is setup like this:

 

Table

So, pickup values 3788, 3522, 3604, 2326, 3058 and then avg it.

 

Can someone help?

 

Thanks.

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@ranbeermakin 

I would suggest this measure - a slight modification of the above reply that ensures the top 5 dates are taken from those where B is not blank:

Average of B Over Last 5 Nonblank Dates = 
VAR Last5Dates =
    CALCULATETABLE ( 
        TOPN ( 5, VALUES ( YourTable[Date] ), YourTable[Date]  ),
        NOT ISBLANK ( YourTable[B] )
    )
RETURN
    CALCULATE ( AVERAGE ( YourTable[B] ), Last5Dates )


Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

@ranbeermakin 

I would suggest this measure - a slight modification of the above reply that ensures the top 5 dates are taken from those where B is not blank:

Average of B Over Last 5 Nonblank Dates = 
VAR Last5Dates =
    CALCULATETABLE ( 
        TOPN ( 5, VALUES ( YourTable[Date] ), YourTable[Date]  ),
        NOT ISBLANK ( YourTable[B] )
    )
RETURN
    CALCULATE ( AVERAGE ( YourTable[B] ), Last5Dates )


Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
Anonymous
Not applicable

Hey Ranbeer,

 

CALCULATE(AVERAGE(Table1[ColumnB]), // Col b is nmberic that we want avg for
TOPN(
5,
Table1,
Table1[Date])
)
 
 
Anonymous
Not applicable

Hello!

 

The CALCULATE expression allows you to compute values based on certain filters, more info here.

So you would say

CALCULATE(AVERAGE(Column Name),Column Name<>BLANK())

And then in order to select the last 5 measures, you can select the column name in the filters selection > Select ‘Top N’ in the drop-down > switch it to Bottom > enter 5.

Or if you have ranked the column by date, and on the filter, select whichever ones you want by adding another filter to the CALCULATE measure:

CALCULATE(AVERAGE(‘Column Name’),’Column Name’<>BLANK(),’Date’ > (Specific Date))

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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