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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rachaelwalker
Resolver III
Resolver III

Lookup Value in another table based on multiple conditions and <= date

I want to analyze our purchase orders and check it against the inventory audit log to analyze the inventory levels for that date.  I have attached my file with sample data and details. The main issue is the audit table only records changes so when using a calendar table, it is not aligning with all audit dates so I need to find the qty of the previous date recorded for that product and warehouse. 

 

https://drive.google.com/file/d/1mhFoVVxsnHDGDhF2ebT5FVoU9P_EkPN0/view?usp=sharing

 

Purchase Orders

Date

Project

PO Number

Product ID

Warehouse

Qty Purchased

 

Inventory Audit

Date 

Product ID

Warehouse

Qty Changed

Qty On Hand

 

Calendar Table

Date

 

Expected Results

rachaelwalker_0-1716933552400.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rachaelwalker 

 

For your question, here is the method I provided:

 

Create measures.

 

 

Project Number = 
CALCULATE(
    MAX('Purchase Orders'[Project Number]), 
    FILTER(
        ALL('Purchase Orders'), 
        'Purchase Orders'[Date Purchased] = MAX('Purchase Orders'[Date Purchased])
    )
)

 

 

 

Qty On Hand = 
var _date = SELECTEDVALUE('Purchase Orders'[Date Purchased])
var _maxdate = 
    CALCULATE(
        MAX('Inventory Audit GROUPED'[Date]), 
        FILTER(
            ALL('Inventory Audit GROUPED'), 
            'Inventory Audit GROUPED'[Date] <= _date 
            && 
            'Inventory Audit GROUPED'[Warehouse] = SELECTEDVALUE('Purchase Orders'[Warehouse])
        )
    )
RETURN 
CALCULATE(
    SELECTEDVALUE('Inventory Audit GROUPED'[Qty On Hand]), 
    FILTER(
        ALL('Inventory Audit GROUPED'), 
        'Inventory Audit GROUPED'[Date] = _maxdate
    )
)

 

 

Here is the result.

 

vnuocmsft_0-1716961774795.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @rachaelwalker 

 

For your question, here is the method I provided:

 

Create measures.

 

 

Project Number = 
CALCULATE(
    MAX('Purchase Orders'[Project Number]), 
    FILTER(
        ALL('Purchase Orders'), 
        'Purchase Orders'[Date Purchased] = MAX('Purchase Orders'[Date Purchased])
    )
)

 

 

 

Qty On Hand = 
var _date = SELECTEDVALUE('Purchase Orders'[Date Purchased])
var _maxdate = 
    CALCULATE(
        MAX('Inventory Audit GROUPED'[Date]), 
        FILTER(
            ALL('Inventory Audit GROUPED'), 
            'Inventory Audit GROUPED'[Date] <= _date 
            && 
            'Inventory Audit GROUPED'[Warehouse] = SELECTEDVALUE('Purchase Orders'[Warehouse])
        )
    )
RETURN 
CALCULATE(
    SELECTEDVALUE('Inventory Audit GROUPED'[Qty On Hand]), 
    FILTER(
        ALL('Inventory Audit GROUPED'), 
        'Inventory Audit GROUPED'[Date] = _maxdate
    )
)

 

 

Here is the result.

 

vnuocmsft_0-1716961774795.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! This worked perfectly. The performance is very slow but it works!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.