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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
data_analytics
Frequent Visitor

LookupValue: Check DateRange for Many-to-Many

I have two unrelated tables with M-2-M

Table A

AccountNumWarehouseItem NumberEFFECTIVE_DATE_KEYEXPIRATION_DATE_KEY
006724WH9ItemPQR2022010120220930
006724WH9ItemPQR2022040120221231
006724WH9ItemPQR2022050120220930

 

Table B

AccountNumWarehouseItem NumberQuantityDeliveryDateKey
006724WH9ItemPQR400020221011
006724WH9ItemPQR500020220131

 

AccountNum, Warehouse, and Item Number can result in multiple rows per table.

I have tried LOOKUPVALUE, NATURALLEFTOUTERJOIN (to denormalize). Results are not as expected.

How do I get Quantity from Table B if TableB.DeliveryDateKey is > TableA.EffectiveDateKey and <ExpirationDateKey? Expected result is:

AccountNumWarehouseItem NumberEFFECTIVE_DATE_KEYEXPIRATION_DATE_KEYQuantityNotes
006724WH9ItemPQR2022010120220930500020220131 bteween 20220101 and 20220930. Hence Qty=5000
006724WH9ItemPQR2022040120221231400020221011 falls between 20220401 and 20221231. hence qty = 4000
006724WH9ItemPQR20220501202209300Nothing found
1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

CALCULATEDCOLUMN=SUMX(FILTER(TableB,TableB[DeliveryDateKey]>TableA[EffectiveDateKey]&&TableB[DeliveryDateKey]<TableA[ExpirationDateKey]&&TableB[AccountNum]=TableA[AccountNum]&&TableB[Warehouse]=TableA[Warehouse]&&TableB[ItemNumber]=TableA[ItemNumber]),TableB[Quantity])

View solution in original post

1 REPLY 1
wdx223_Daniel
Super User
Super User

CALCULATEDCOLUMN=SUMX(FILTER(TableB,TableB[DeliveryDateKey]>TableA[EffectiveDateKey]&&TableB[DeliveryDateKey]<TableA[ExpirationDateKey]&&TableB[AccountNum]=TableA[AccountNum]&&TableB[Warehouse]=TableA[Warehouse]&&TableB[ItemNumber]=TableA[ItemNumber]),TableB[Quantity])

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.