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

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
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.