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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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

 

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.