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
Brotedo
Helper I
Helper I

Match Item Prices over Time (with lookupvalue)?

I have two tables, a FactSales table and an ItemPrice table. The FactSales table has an item number and an invoice date. The ItemPrice table has an item number, an effective date, an expiration date, and a price (so the item number is not unique in this table - an item has multiple entries for prices at different times). I want to pull the price of the item at the time of the invoice into my FactSales table.

I tried to embed a lookupvalue in a calculate with filters on the ItemPrice table based on eff. and exp. date, but I realized I couldn't actually use lookupvalue inside calculate. I'm stuck on this one.

Table examples:

ItemNumberEff. DateExp. DatePrice
1A1/1/20201/1/2021$10
1A1/1/2021 

$12

 

ItemNumberInvoiceDatePrice (What I want)
1A6/3/2020$10
1A4/1/2021$12
1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Brotedo ,

You can create a calculated column in the table 'FactSales' as below to get it, please find the details in the attachment.

Price = 
CALCULATE (
    MAX ( 'ItemPrice'[Price] ),
    FILTER (
        'ItemPrice',
        'ItemPrice'[ItemNumber] = 'FactSales'[ItemNumber]
            && 'FactSales'[InvoiceDate] >= 'ItemPrice'[Eff. Date]
            && 'FactSales'[InvoiceDate]
                <= IF (
                    ISBLANK ( 'ItemPrice'[Exp. Date] ),
                    DATE ( 9999, 12, 31 ),
                    'ItemPrice'[Exp. Date]
                )
    )
)

vyiruanmsft_0-1681955040446.png

Best Regards

Community Support Team _ Rena
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
Ashish_Mathur
Super User
Super User

Hi,

In the Query Editor, insert Today's data in place of blanks in the Exp. Date column.  In Table2, write this calculated column formula

Price = calculate(SUM('Table1'[Price]),filter('Table1','Table1'[Itemnumber]=earlier('Table2'[Itemnumber])&&'Table1'[Eff. Date]<=earlier('Table2'[Date])&&'Table1'[Exp. Date]>earlier('Table2'[Date])))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yiruan-msft
Community Support
Community Support

Hi @Brotedo ,

You can create a calculated column in the table 'FactSales' as below to get it, please find the details in the attachment.

Price = 
CALCULATE (
    MAX ( 'ItemPrice'[Price] ),
    FILTER (
        'ItemPrice',
        'ItemPrice'[ItemNumber] = 'FactSales'[ItemNumber]
            && 'FactSales'[InvoiceDate] >= 'ItemPrice'[Eff. Date]
            && 'FactSales'[InvoiceDate]
                <= IF (
                    ISBLANK ( 'ItemPrice'[Exp. Date] ),
                    DATE ( 9999, 12, 31 ),
                    'ItemPrice'[Exp. Date]
                )
    )
)

vyiruanmsft_0-1681955040446.png

Best Regards

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

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.