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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
SteveWave
Frequent Visitor

Find two last non-blank values in column

Dear Community,

 

I simply need the find the last & previous non-blank value in the [Value] column (see image in red) and get the difference.

Actually, I tried and got the last value of 210 T, but struggled to find the previous one.

 

Trend = VAR _last =

MAXX( FILTER('Table', NOT ISBLANK([Value])) )

RETURN CALCULATE(

MAX('Table'[Value]),

ALL( 'Table'), 'Table'[Value] = _last )

 

Bild1.png

Many thanks for your ideas.

 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

HI @SteveWave ,

To find the difference between the last and previous non-blank values in the [Value] column, you’ll need to retrieve both values separately and then calculate the difference. Here’s a DAX measure that should help:

 

Trend = 
VAR LastValueDate = 
    MAXX(FILTER('Table', NOT(ISBLANK('Table'[Value]))), 'Table'[Column1])
VAR LastValue = 
    CALCULATE(MAX('Table'[Value]), 'Table'[Column1] = LastValueDate)

VAR PreviousValueDate = 
    MAXX(
        FILTER(
            'Table', 
            NOT(ISBLANK('Table'[Value])) && 'Table'[Column1] < LastValueDate
        ), 
        'Table'[Column1]
    )
VAR PreviousValue = 
    CALCULATE(MAX('Table'[Value]), 'Table'[Column1] = PreviousValueDate)

RETURN 
    IF(NOT(ISBLANK(LastValue)) && NOT(ISBLANK(PreviousValue)), LastValue - PreviousValue, BLANK())

 

 

As you can see, in my sample the result was 60 comming from diference of 210-150:

Bibiano_Geraldo_0-1731346351331.png

 

Make sure to replace table and columns names with your owns.

 

And if this post help you, please consider to mark it as solution and give a Kudo.

 

Thank you

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @SteveWave ,

 

How is the situation now? If the problem has been solved, please accept replies you find helpful as solutions. If not, you can try this DAX to get the value of the penultimate row and the value is not empty, and alternatively, you can change the value of the ordernumber to get the value anywhere you want.

Measure = 
var ordernumber = 2
var ordertable = ADDCOLUMNS(
        'Table',
        "Rank", 
        RANKX(
            FILTER('Table',NOT ISBLANK('Table'[Value])),
            'Table'[Date],
            ,
            DESC,
            DENSE
        )
    )
    RETURN
    CALCULATE(MAX('Table'[Value]),FILTER(ordertable,[Rank]=ordernumber))

vmengmlimsft_0-1731396724403.png

 

 

 

Best regards,

Mengmeng Li

 

ThxAlot
Super User
Super User

ThxAlot_2-1731355271753.png

ThxAlot_1-1731355214490.png

ThxAlot_3-1731355881031.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Bibiano_Geraldo
Super User
Super User

HI @SteveWave ,

To find the difference between the last and previous non-blank values in the [Value] column, you’ll need to retrieve both values separately and then calculate the difference. Here’s a DAX measure that should help:

 

Trend = 
VAR LastValueDate = 
    MAXX(FILTER('Table', NOT(ISBLANK('Table'[Value]))), 'Table'[Column1])
VAR LastValue = 
    CALCULATE(MAX('Table'[Value]), 'Table'[Column1] = LastValueDate)

VAR PreviousValueDate = 
    MAXX(
        FILTER(
            'Table', 
            NOT(ISBLANK('Table'[Value])) && 'Table'[Column1] < LastValueDate
        ), 
        'Table'[Column1]
    )
VAR PreviousValue = 
    CALCULATE(MAX('Table'[Value]), 'Table'[Column1] = PreviousValueDate)

RETURN 
    IF(NOT(ISBLANK(LastValue)) && NOT(ISBLANK(PreviousValue)), LastValue - PreviousValue, BLANK())

 

 

As you can see, in my sample the result was 60 comming from diference of 210-150:

Bibiano_Geraldo_0-1731346351331.png

 

Make sure to replace table and columns names with your owns.

 

And if this post help you, please consider to mark it as solution and give a Kudo.

 

Thank you

lbendlin
Super User
Super User

Use TOPN(2,...  filter on the value column and sort on the date column.

 

Then convert the resulting table to your final result

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors