Function Problems

DAX Formula to Find the Previous Purchase Order by Supplier

Huma Ashraf ChHuma Ashraf Ch Nov 3, 2026 869 views

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.

How to Find the Previous Purchase Order by Supplier Using DAX
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Data View

Navigate to the Data view in Power BI Desktop or open the Power Pivot window in Microsoft Excel.

2
Create a New Calculated Column

Click on 'New Column' under the Modeling or Table Tools tab to add a blank calculated column to your dataset.

3
Enter the DAX Formula

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])))

4
Apply and Verify

Press Enter to apply the DAX calculation. Review the new column to ensure it displays the correct preceding PO number for each row.

Find Previous Purchase Order Using Numeric PO Numbers
Understanding the EARLIER function: The EARLIER function is crucial here as it creates a row context, allowing the formula to compare the current row's Supplier Name and PO Number against the entire dataset iteratively.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website to download and install the free, lightweight WPS Office suite.
  2. 2. Open Your Excel File: Launch WPS Spreadsheet and open your existing dataset seamlessly, retaining all original data formatting.
  3. 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.
Completely free, lightweight, and fast to installFully compatible with Microsoft Excel (.xlsx) formatsSupports powerful standard functions like MAXIFS, INDEX, and MATCHFamiliar user interface requiring zero learning curve
microsoft office alternative - wps office

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.