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 August 31st. Request your voucher.

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
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.