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
kaledjeff
Advocate I
Advocate I

Previous Purchase

Hello,

 

I have a list of purchase orders for all of our customers. I would like to know how to get the previous purchase order for a customer.

 

Please keep in mind the numbers of purchase orders are randomly generated.

 

 

12.png

 

 

 

 

 

 

 

I very much appreaciate your help.

 

BR

1 ACCEPTED SOLUTION

@kaledjeff

 

Or this Calculated Column

 

Column =
VAR myLastDate =
    CALCULATE (
        MAX ( 'Table1'[Purchase Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] < EARLIER ( 'Table1'[Purchase Date] )
        )
    )
RETURN
    CALCULATE (
        FIRSTNONBLANK ( 'Table1'[Purchase Order], 1 ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] = myLastDate
        )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

8 REPLIES 8
Phil_Seamark
Employee
Employee

Hi @kaledjeff

 

This calculated column is close

 

Previous Order (Desired Result) = 
VAR myLastDate =    
    CALCULATE(
           MAX('Table1'[Purchase Date]),
           FILTER(
               'Table1','Table1'[Client] = EARLIER('Table1'[Client]) && 
               'Table1'[Purchase Date] < EARLIER('Table1'[Purchase Date])
           )
          )
RETURN CALCULATE(
            MAX('Table1'[Purchase Order]),
            FILTER('Table1','Table1'[Purchase Date] = myLastDate)
            )     

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank you @Phil_Seamark @Zubair_Muhammad for help.

 

I tested the calculated column by @Zubair_Muhammad and it worked like a charm.

 

@Phil_Seamark, I will test the function and let you know.

 

I appreacite your help.

 

BR

HI @kaledjeff

 

They are essentially the same code, except you don't actually need to use the ALLEXCEPT function.  It doesn't do anything in calculated columns  - so could just slow down the calculation. 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @kaledjeff

 

This doesn't grab the MAX purchase order number.  It uses the MAX function to find the newest of all purchase orders in the past.  It should give you what you need. 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark

 

I agree with you !


Your formula works while the one of @Zubair_Muhammad give me an error message : not enough memory to proceed.

 

Your formula helps me a lot but I steel have an issue.

 

It sum all "previous order" if there have been several order the same day.

Is there a way to retrieve only the last amount without summing all of them ?

I try to integrate LASTNONBLANK in your formula without success.

 

Any idea will be appreciated 🙂

 

Have a nice day

Nicolas

Thank you very much for quick reply.

 

But it isn't exactly what I need. The purchase number is created randomly. I can't take the max.

 

BR

@kaledjeff

 

I think @Phil_Seamark column should work.

 

Nevertheless try the following as well

 

First a MEASURE

 

Measure =
VAR myLastDate =
    CALCULATE (
        MAX ( 'Table1'[Purchase Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] < SELECTEDVALUE ( 'Table1'[Purchase Date] )
        )
    )
RETURN
    CALCULATE (
        FIRSTNONBLANK ( 'Table1'[Purchase Order], 1 ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] = myLastDate
        )
    )

 

 


Regards
Zubair

Please try my custom visuals

@kaledjeff

 

Or this Calculated Column

 

Column =
VAR myLastDate =
    CALCULATE (
        MAX ( 'Table1'[Purchase Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] < EARLIER ( 'Table1'[Purchase Date] )
        )
    )
RETURN
    CALCULATE (
        FIRSTNONBLANK ( 'Table1'[Purchase Order], 1 ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Client] ),
            'Table1'[Purchase Date] = myLastDate
        )
    )

Regards
Zubair

Please try my custom visuals

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.