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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Second Last Value

Hello

 

I have successfully produced the last value using this calculation:

Last Value =
SUMX(FILTER('Market Prices','Market Prices'[Date]=LASTDATE('Market Prices'[Date])),'Market Prices'[Value])

 

Which gets used by:

 

Last Trans =
VAR Last_Date = Lastdate('Market Prices'[Date])

RETURN
CALCULATE([Last Value],
    Filter(All('Market Prices'[Date]),
    'Market Prices'[Date] = Last_Date))
 
Fergo_0-1675136725145.png

 

But I am having trouble getting second last transaction (Transaction before last transaction).  
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Here I suggest you to try below codes to create [Last Trans] and [Second Last Trans] measures.

Second Last Trans =
VAR _Last_Date =
    MAXX (
        FILTER (
            ALL ( 'Market Prices' ),
            'Market Prices'[Symbol] = MAX ( 'Market Prices'[Symbol] )
                && 'Market Prices'[Date] < MAX ( 'Market Prices'[Date] )
        ),
        'Market Prices'[Date]
    )
RETURN
    CALCULATE (
        SUM ( 'Market Prices'[Value] ),
        FILTER ( 'Market Prices', 'Market Prices'[Date] = _Last_Date )
    )
Last Trans = 
VAR _Last_Date =
    MAXX (
        FILTER (
            ALL ( 'Market Prices' ),
            'Market Prices'[Symbol] = MAX ( 'Market Prices'[Symbol] )
        ),
        'Market Prices'[Date]
    )
RETURN
    CALCULATE (
        SUM ( 'Market Prices'[Value] ),
        FILTER ( 'Market Prices', 'Market Prices'[Date] = _Last_Date )
    )

My Sample:

RicoZhou_1-1675761718814.png

Result is as below.

RicoZhou_0-1675761699026.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Cheers, that looks great.

Anonymous
Not applicable

Hi @Anonymous ,

 

Here I suggest you to try below codes to create [Last Trans] and [Second Last Trans] measures.

Second Last Trans =
VAR _Last_Date =
    MAXX (
        FILTER (
            ALL ( 'Market Prices' ),
            'Market Prices'[Symbol] = MAX ( 'Market Prices'[Symbol] )
                && 'Market Prices'[Date] < MAX ( 'Market Prices'[Date] )
        ),
        'Market Prices'[Date]
    )
RETURN
    CALCULATE (
        SUM ( 'Market Prices'[Value] ),
        FILTER ( 'Market Prices', 'Market Prices'[Date] = _Last_Date )
    )
Last Trans = 
VAR _Last_Date =
    MAXX (
        FILTER (
            ALL ( 'Market Prices' ),
            'Market Prices'[Symbol] = MAX ( 'Market Prices'[Symbol] )
        ),
        'Market Prices'[Date]
    )
RETURN
    CALCULATE (
        SUM ( 'Market Prices'[Value] ),
        FILTER ( 'Market Prices', 'Market Prices'[Date] = _Last_Date )
    )

My Sample:

RicoZhou_1-1675761718814.png

Result is as below.

RicoZhou_0-1675761699026.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.