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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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