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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-rzhou-msft
Community Support
Community Support

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.

v-rzhou-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.