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
oliverwebb
New Member

Filtering FIRSTNONBLANKVALUE - can't seem to figure it out.

Hi all,

 

I have a table in my Dataset that has:

  • Four columns of unique data
  • Two additional columns
    • Date
    • Area

There are other columns that come from the query but I don't need those. It looks like this (I've filtered it down to only two locations for ease of screenshotting):

oliverwebb_0-1642080715584.png

What I'm having a problem with is filtering the following down to the first non-blank value:

  • Rate per 100k (last 7 days rolling)
  • Cases Last 7 Days

I managed at one point to return the date of the first non-blank value, but I got stumped there and couldn't do anything else. I even tried to use the Measure that returned the date to filter but I couldn't get that to work either.

 

I found an article online which seems to do what I want, and wrote the following:

Latest_Rate_Per_100k_Rolling = 
VAR LastNonBlankDate =
 CALCULATE (
 LASTNONBLANK ( LTLA[date], 1 ),
 FILTER (
 ALL ( LTLA ),
 LTLA[date] <= EARLIER ( LTLA[date] )
 && NOT ( ISBLANK ( LTLA[Rate per 100k (last 7 days rolling)] ) )
 )
 )
RETURN
 CALCULATE (
 SUM ( LTLA[Rate per 100k (last 7 days rolling)] ),
 FILTER ( ALL ( LTLA ), LTLA[date] = LastNonBlankDate )
 )

But this gives me the error:

EARLIER/EARLIEST refers to an earlier row context which doesn't exist.

Any ideas on how to do this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @oliverwebb,

You can try to use the following measure format to get the last value and return tags, then you can use it on 'visual level filter' to filter records based on tags:

Latest Rate_Per_100k_Rolling =
VAR currDate =
    MAX ( LTLA[date] )
VAR _lastDate =
    CALCULATE (
        MAX ( LTLA[date] ),
        FILTER (
            ALLSELECTED ( LTLA ),
            LTLA[date] <= currDate
                && LTLA[Rate per 100k (last 7 days rolling)] > 0
        ),
        VALUES ( LTLA[AreaCode] )
    )
VAR lastValue =
    CALCULATE (
        MAX ( LTLA[Rate per 100k (last 7 days rolling)] ),
        FILTER ( ALLSELECTED ( LTLA ), LTLA[date] = _lastDate ),
        VALUES ( LTLA[AreaCode] )
    )
RETURN
    IF ( MAX ( LTLA[Rate per 100k (last 7 days rolling)] ) = lastValue, "Y", "N" )

Applying a measure filter in Power BI - SQLBI

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@oliverwebb , if this measure use max

 

Latest_Rate_Per_100k_Rolling = 
VAR LastNonBlankDate =
 CALCULATE (
 LASTNONBLANK ( LTLA[date], 1 ),
 FILTER (
 ALL ( LTLA ),
 LTLA[date] <= MAX( LTLA[date] )
 && NOT ( ISBLANK ( LTLA[Rate per 100k (last 7 days rolling)] ) )
 )
 )
RETURN
 CALCULATE (
 SUM ( LTLA[Rate per 100k (last 7 days rolling)] ),
 FILTER ( ALL ( LTLA ), LTLA[date] = LastNonBlankDate )
 )

 

 

Also, check if lastnonblankvalue can helphttps://www.linkedin.com/pulse/five-recent-power-bi-functions-you-should-use-more-often-amit-chandak

 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

This doesn't seem to work - it returns 637679.5 but if I check the table it should be 1195.7 for the latest record.

Anonymous
Not applicable

Hi @oliverwebb,

You can try to use the following measure format to get the last value and return tags, then you can use it on 'visual level filter' to filter records based on tags:

Latest Rate_Per_100k_Rolling =
VAR currDate =
    MAX ( LTLA[date] )
VAR _lastDate =
    CALCULATE (
        MAX ( LTLA[date] ),
        FILTER (
            ALLSELECTED ( LTLA ),
            LTLA[date] <= currDate
                && LTLA[Rate per 100k (last 7 days rolling)] > 0
        ),
        VALUES ( LTLA[AreaCode] )
    )
VAR lastValue =
    CALCULATE (
        MAX ( LTLA[Rate per 100k (last 7 days rolling)] ),
        FILTER ( ALLSELECTED ( LTLA ), LTLA[date] = _lastDate ),
        VALUES ( LTLA[AreaCode] )
    )
RETURN
    IF ( MAX ( LTLA[Rate per 100k (last 7 days rolling)] ) = lastValue, "Y", "N" )

Applying a measure filter in Power BI - SQLBI

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.