DAX Formula to Find the Previous Purchase Order by Supplier
Question details
The user needs a DAX formula to identify the most recent previous purchase order for a specific supplier based on either the PO number sequence or the purchase date.

- Product
- Power BI / Excel Power Pivot
- Device & OS
- not provided
- Scenario
- Analyzing procurement data to retrieve the immediately preceding purchase order number for each supplier in a dataset.
- Observed behavior
- Requires a calculated DAX column that correctly evaluates and displays the previous PO number relative to the current row's transaction.
Ensure your dataset is properly formatted as a table and verify whether your Purchase Order numbers are stored as numeric values or alphanumeric text, as this dictates the logical comparisons required in your DAX formula.
Find Previous Purchase Order Using Numeric PO Numbers
Use this method when your purchase order numbers are strictly sequential integer values.
By using a combination of CALCULATE, MAX, FILTER, and EARLIER functions, you can instruct the data model to look at the current row's supplier and return the highest PO number that is still mathematically lower than the current row's PO number.
Navigate to the Data view in Power BI Desktop or open the Power Pivot window in Microsoft Excel.
Click on 'New Column' under the Modeling or Table Tools tab to add a blank calculated column to your dataset.
Type the following formula into the formula bar: Previous PO = CALCULATE(MAX(Data[PO No]), FILTER(Data, Data[Supplier Name] = EARLIER(Data[Supplier Name]) && Data[PO No] < EARLIER(Data[PO No])))
Press Enter to apply the DAX calculation. Review the new column to ensure it displays the correct preceding PO number for each row.

Retrieve Previous Purchase Order Based on Purchase Date
Use this method if your PO numbers contain text (alphanumeric) or if 'previous' strictly means the chronologically earlier order.
Handle Complex Data Lookups Easily with WPS Spreadsheet
While DAX and Power BI are excellent for advanced data modeling, many everyday data tasks can be handled without complex data models. WPS Spreadsheet is a robust, free alternative to Microsoft Excel that offers comprehensive standard lookup functions to achieve similar results quickly.
- 1. Download WPS Office: Visit the official WPS website to download and install the free, lightweight WPS Office suite.
- 2. Open Your Excel File: Launch WPS Spreadsheet and open your existing dataset seamlessly, retaining all original data formatting.
- 3. Use Standard Formulas: Utilize built-in spreadsheet functions such as MAXIFS and XLOOKUP to easily retrieve previous dates and purchase order numbers without needing DAX.

Frequently Asked Questions
What if my PO numbers are stored as text (e.g., PO-1001)?
If your PO numbers contain letters or symbols, you cannot use a simple mathematical '<' operator on the PO column. You must rely on a chronological Date column or an Index column to determine the correct order, and then retrieve the corresponding PO text.
Why does the EARLIER function return an error in my measure?
The EARLIER function requires a row context to evaluate properly. It can only be used successfully within a calculated column, or inside iterator functions like FILTER and SUMX. Ensure you are creating a 'New Column' in your data model rather than a DAX Measure.
Can I achieve this without DAX using standard spreadsheet formulas?
Yes. In standard spreadsheet software like WPS Spreadsheet or Excel, you can use the MAXIFS function to find the maximum date for a supplier that is less than the current row's date, and then use an INDEX/MATCH or XLOOKUP formula to retrieve the matching PO number.




