cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bfdijkstra Frequent Visitor
Frequent Visitor

Finding the most recent value in another table

Hi everyone,

 

I'm trying to find a solution for the following issue.

 

I have two tables:

Salesinvoice (salesdate, articlenumber)

Purchaseinvoice (purchasedate, articlenumber, purchaseprice)

 

I'm trying to create a measure in Salesinvoice that, based on the salesdate, selects the latest purchaseprice.

So, the salesdate >= purchasedate && MAX(purchasedate).

 

Can someone please help me?

1 ACCEPTED SOLUTION

Accepted Solutions
v-cherch-msft Super Contributor
Super Contributor

Re: Finding the most recent value in another table

Hi @bfdijkstra

 

You may use below measure. Show the simplified sample as below:

LatestPrice =
CALCULATE (
    MAX ( Purchaseinvoice[purchaseprice] ),
    TOPN (
        1,
        FILTER (
            Purchaseinvoice,
            Purchaseinvoice[articlenumber] = MAX ( Salesinvoice[articlenumber] )
                && Purchaseinvoice[purchasedate] <= MAX ( Salesinvoice[salesdate] )
        ),
        Purchaseinvoice[purchasedate], DESC
    )
)

1.png

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
v-cherch-msft Super Contributor
Super Contributor

Re: Finding the most recent value in another table

Hi @bfdijkstra

 

You may use below measure. Show the simplified sample as below:

LatestPrice =
CALCULATE (
    MAX ( Purchaseinvoice[purchaseprice] ),
    TOPN (
        1,
        FILTER (
            Purchaseinvoice,
            Purchaseinvoice[articlenumber] = MAX ( Salesinvoice[articlenumber] )
                && Purchaseinvoice[purchasedate] <= MAX ( Salesinvoice[salesdate] )
        ),
        Purchaseinvoice[purchasedate], DESC
    )
)

1.png

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
bfdijkstra Frequent Visitor
Frequent Visitor

Re: Finding the most recent value in another table

Hi @v-cherch-msft,

 

Thanks! That worked well for me!

 

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 134 members 1,713 guests
Please welcome our newest community members: