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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Show previous value of specific customer

Hi everyone,

 

I would like to make calculations on order dates based on the previous order dates of specific customers.

So far, I've add a "SalesSequence" column in my "Sales" table using this Dax formula:

 

SalesSequence =

VAR CurrentOrderDate = Sales[OrderDate]
RETURN
COUNTROWS(
    FILTER(
        CALCULATETABLE(
            Sales;
            ALLEXCEPT(Sales;Sales[AccountId])
        );
        Sales[OrderDate] <= CurrentOrderDate
    )
)

 

This should help me get the previous order date of a specific customer.

 

Here is an example of the column "PreviousOrderDate" I'd like to add to my "Sales" table:

AccountIdOrderDateSalesAmountSalesSequencePreviousOrderDate
a101.01.20151001 
a112.01.2015200201.01.2015
b123.02.20161401 
b120.10.201750223.02.2016
a114.10.2016100312.01.2015
c120.08.20162001 
a112.10.2017300414.10.2016

 

 

Your help will be much appreciated !

 

Thanks in advance !

 

R.

1 ACCEPTED SOLUTION

@Anonymous

 

Try with this: 

Column 2 =
CALCULATE (
    VALUES ( Table1[OrderDate] ),
    FILTER (
        ALL ( Table1 ),
        Table1[SalesSequence]
            = EARLIER ( Table1[SalesSequence] ) - 1
            && Table1[AccountId] = EARLIER ( Table1[AccountId] )
    )
)

Regards

Victor

 




Lima - Peru

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@Anonymous

 

Hi, try with this calculated column.

 

PreviousOrderDate =
CALCULATE (
    LASTNONBLANK ( Table1[OrderDate]; Table1[OrderDate] ),
    FILTER (
        Table1,
        Table1[OrderDate] < EARLIER ( Table1[OrderDate] )
            && Table1[AccountId] = EARLIER ( Table1[AccountId] )
    )
)

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

@Vvelarde

 

Thanks for your answer.

Is there another way to do it? Because I tried yours and it's still calculating 15 minutes later (there is +3.8M rows in my sales table).

@Anonymous

 

Try with this: 

Column 2 =
CALCULATE (
    VALUES ( Table1[OrderDate] ),
    FILTER (
        ALL ( Table1 ),
        Table1[SalesSequence]
            = EARLIER ( Table1[SalesSequence] ) - 1
            && Table1[AccountId] = EARLIER ( Table1[AccountId] )
    )
)

Regards

Victor

 




Lima - Peru
Anonymous
Not applicable

@Vvelarde

 

It works like a charm !

 

Thank you very much. 🙂

 

R.

 

 

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.

Top Solution Authors
Top Kudoed Authors