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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DaxNewbies
New Member

Please help : Second to Last Date in Virtual Table

Dear all,

 

Could anyone help me with the formula? I tried to use the following formula to access the previous row (second to last date) in a virtual table but it didn't work as expected.


VAR Product1 =
    SELECTEDVALUE ( 'Product Master'[ProductKey] )
VAR Customer1 =
    SELECTEDVALUE ( 'Customer Master'[CustomerKey] )
VAR Table1 =
    SUMMARIZECOLUMNS (
        'Sales Date'[Date],
        'Customer Master'[Customer Name],
        'Product Master'[Product Name],
        "Sales", [Total Net Sales]
    )
VAR SalesLastDate =
    CALCULATE (
        LASTDATE ( 'Sales Date'[Date] ),
        'Sales Fact'[ProductKey] = Product1,
        'Sales Fact'[CustomerKey] = Customer1
    )
RETURN
    ADDCOLUMNS (
        Table1,
        "LastOrderDate",
            CALCULATE (
                CALCULATE (
                    LASTDATE ( 'Sales Date'[Date] ),
                    FILTER ( 'Sales Date', 'Sales Date'[Date] <> saleslastdate )
                ),
                'Sales Fact'[ProductKey] = Product1,
                'Sales Fact'[CustomerKey] = Customer1
            )
    )

 

Could DAX let us access the previous row (Like using earlier or Var. in a calculated column?)

Here is my result

Screenshot 2020-10-19 175616.png






My objective is to averagex the result of datediff between date and lastorderdate in a virtual table format.

(To get average order date duration for each product & each customer)

Thank you in advance for your advices.

1 REPLY 1
amitchandak
Super User
Super User

@DaxNewbies ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.