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
Anonymous
Not applicable

How to get value from another table based on multiple criteria

Hello,

 

I'm in stuck with my problem. Let's say I have 2 tables: Quotations and Shipments:

 

Quotations table:

BranchDepartmentQuoteIDLocal ClientSrvLevelOriginDestinationStart DateExpiry Date
BR2241QMT200002851Customer1LIFNLRTMDEBRV2018.06.022018.06.30
BR2241QMT200002852Customer2FILNLRTMDEBRV2018.06.022018.06.15
BR2241QMT200002853Customer4LILKRPUSDEBRV2018.06.022018.06.30
BR2241QMT200002854Customer5LIDKRPUSDEBRV2018.06.022018.06.30
BR2241QMT200002855Customer7LIFDEHAMDEBRV2018.06.022018.06.30
BR2241QMT200002856Customer8LIFDEHAMDEBRV2018.06.022018.06.30
BR2241QMT200002857Customer9LIDCNSHADEBRV2018.06.032018.06.15
BR2241QMT200002858Customer10LIFDEHAMDEBRV2018.06.012018.06.30

 

Shipments table:

 

BranchDepartmentShipment IDLocal ClientSrv LevelOriginDestinationDepartureQuoteID
BR2241SHP2800120Customer1LILNLRTMDEBRV2018.05.29 
BR2241SHP2800129Customer10LIFDEHAMDEBRV2018.06.06 
BR2241SHP2800130Customer10LIFDEHAMDEBRV2018.06.24 
BR2241SHP2800121Customer2LIFNLRTMDEBRV2018.06.10 
BR2241SHP2800122Customer3LIFDEHAMDEBRV2018.06.10 
BR2241SHP2800123Customer4LILKRPUSDEBRV2018.04.30 
BR2241SHP2800124Customer5LIFKRPUSDEBRV2018.06.16 
BR2241SHP2800125Customer6LIFCNSHADEBRV2018.06.16 
BR2241SHP2800126Customer7LIFDEHAMDEBRV2018.06.16 
BR2241SHP2800127Customer8LIFDEHAMDEBRV2018.06.03 
BR2241SHP2800131Customer8LIFDEHAMDEBRV2018.06.20 
BR2241SHP2800128Customer9LILCNSHADEBRV2018.06.15 

 

My goal is to transfer QuoteID from Quotations table into Shipments table if such conditions are met:

 

Branch=Branch

Department=Department

LocalClient=LocalClient

SrvLevel=SrvLevel

Origin=Origin

Destination=Destination

Departure is between StartDate and ExpiryDate

 

My expected result in Shipments table should look like this:

 

BranchDepartmentShipment IDLocal ClientService LevelOriginDestinationDepartureQuoteID
BR2241SHP2800120Customer1LILNLRTMDEBRV2018.05.29 
BR2241SHP2800129Customer10LIFDEHAMDEBRV2018.06.06QMT200002858
BR2241SHP2800130Customer10LIFDEHAMDEBRV2018.06.24QMT200002858
BR2241SHP2800121Customer2LIFNLRTMDEBRV2018.06.10 
BR2241SHP2800122Customer3LIFDEHAMDEBRV2018.06.10 
BR2241SHP2800123Customer4LILKRPUSDEBRV2018.04.30QMT200002853
BR2241SHP2800124Customer5LIFKRPUSDEBRV2018.06.16 
BR2241SHP2800125Customer6LIFCNSHADEBRV2018.06.16 
BR2241SHP2800126Customer7LIFDEHAMDEBRV2018.06.16QMT200002855
BR2241SHP2800127Customer8LIFDEHAMDEBRV2018.06.03QMT200002856
BR2241SHP2800131Customer8LIFDEHAMDEBRV2018.06.20QMT200002856
BR2241SHP2800128Customer9LILCNSHADEBRV2018.06.15 

 

 

Thanks in advance!

 

Tomas

 

 

6 REPLIES 6
vmakhija
Post Prodigy
Post Prodigy

Hello


I created following columns 

 

In Quotations table -

1. Concat = Quotations[Branch] & Quotations[Department] & Quotations[Local Client] & Quotations[SrvLevel] & Quotations[Origin] & Quotations[Destination]

 

In Shipments table -

1. Concat = Shipments[Branch] & Shipments[Department] & Shipments[Local Client] & Shipments[Srv Level] & Shipments[Origin] & Shipments[Destination]

 

2. QuoteID =
IF(ISBLANK(LOOKUPVALUE(Quotations[Branch],Quotations[Concat],Shipments[Concat])),"",
CALCULATE(VALUES(Quotations[QuoteID]),
FILTER(Quotations,Shipments[Departure]>Quotations[Start Date] && Shipments[Departure] < Quotations[Expiry Date]),FILTER(Quotations,Quotations[Concat]=Shipments[Concat]) )
)

 

You might have to play with QuoteID field a little to replace "greater than" or "less than" with appropriate "greater than or equal to" or "less than or equal to"

 

It gives me correct results otherwise -

 

QuoteIDShipment IDOriginLocal ClientDestinationBranch
 SHP2800123KRPUSCustomer4DEBRVBR2
 SHP2800120NLRTMCustomer1DEBRVBR2
 SHP2800121NLRTMCustomer2DEBRVBR2
 SHP2800122DEHAMCustomer3DEBRVBR2
 SHP2800124KRPUSCustomer5DEBRVBR2
 SHP2800125CNSHACustomer6DEBRVBR2
 SHP2800128CNSHACustomer9DEBRVBR2
QMT200002855SHP2800126DEHAMCustomer7DEBRVBR2
QMT200002856SHP2800127DEHAMCustomer8DEBRVBR2
QMT200002856SHP2800131DEHAMCustomer8DEBRVBR2
QMT200002858SHP2800129DEHAMCustomer10DEBRVBR2
QMT200002858SHP2800130DEHAMCustomer10DEBRVBR2

 

 

Regards

Anonymous
Not applicable

Hello @vmakhija,

 

I've worked with your formula but still can't receive expected results. Please take a look at my file in below link and let me know what I am doing wrong.

 

Shipments vs Quotes

 

many thanks in advance!

ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous,

 

I am unsure about your expected result. When I use the following, I get the below results:

 

QuoteID1 = 
IF (
    AND (
        Shipments[Departure] >= RELATED ( Quotations[Start Date] ),
        Shipments[Departure] <= RELATED ( Quotations[Expiry Date] )
    ),
    LOOKUPVALUE (
        Quotations[QuoteID],
        Quotations[Branch], Shipments[Branch],
        Quotations[Department], Shipments[Department],
        Quotations[Local Client], Shipments[Local Client],
        Quotations[SrvLevel], Shipments[Srv Level],
        Quotations[Origin], Shipments[Origin],
        Quotations[Destination], Shipments[Destination]
    )
)
QuoteID2 = 
LOOKUPVALUE (
        Quotations[QuoteID],
        Quotations[Branch], Shipments[Branch],
        Quotations[Department], Shipments[Department],
        Quotations[Local Client], Shipments[Local Client],
        Quotations[SrvLevel], Shipments[Srv Level],
        Quotations[Origin], Shipments[Origin],
        Quotations[Destination], Shipments[Destination]
)

1.PNG

 

I am also unsure of performance as well.

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

Hello @ChrisMendoza,

 

Trying to follow your guideline but below error occurs:

 

Capture3.PNG

 

what am I doing wrong?

 

Thanks, Tomas

@Anonymous, 

 

Seems like you do not have a relationship between the two tables. When I loaded your sample tables, Power BI established the relationship as the below for me:

 

1.png

 

Is your's not similar?

 

For Reference RELATED ( ) 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

Hi @ChrisMendoza,

 

Relation is working if LocalClient is unique but if I add another Quotation for the same client but different Start and Expiry dates (very last  row in below table) then relations dissapearring and your formula is not working.

 

BranchDepartmentQuoteIDLocal ClientSrvLevelOriginDestinationStart DateExpiry Date

BR2241QMT200002851Customer1LIFNLRTMDEBRV2018.06.022018.06.30
BR2241QMT200002852Customer2FILNLRTMDEBRV2018.06.022018.06.15
BR2241QMT200002853Customer4LILKRPUSDEBRV2018.06.022018.06.30
BR2241QMT200002854Customer5LIDKRPUSDEBRV2018.06.022018.06.30
BR2241QMT200002855Customer7LIFDEHAMDEBRV2018.06.022018.06.30
BR2241QMT200002856Customer8LIFDEHAMDEBRV2018.06.022018.06.30
BR2241QMT200002857Customer9LIDCNSHADEBRV2018.06.032018.06.15
BR2241QMT200002858Customer10LIFDEHAMDEBRV2018.06.012018.06.30
BR2241QMT200002859Customer10LIFDEHAMDEBRV2018.07.012018.07.31

 

Any thoughts how to solve such case?

 

Thanks in advance!

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.