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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
sarthaks
Helper III
Helper III

Lookup using DAX

Hi All,

 

I have two tables: Cargo and Location Detials (Its a lookup/master table) and below are some sample data

 

 

Cargo Table:



CargoId	 Origin 	 Destination
1	   01	           04
2	   02	           05
3	   03	           06


Location Details



LocationID	  LocationName
    01	             LOC01
    02	             LOC02
    03	             LOC03
    04	             LOC04
    05	             LOC05
    06	             LOC06

 

Requirement is to replace the Origin and Destination columns in Cargo table with actual location name from the Location Details master table.

 

Please let me know how to achieve using DAX, i tried to create relationship and use LookUP but its not working as we cant maintain relationship with lookup table twice (one using Origin and LocationName, other using Destination and LocationName)

 

Please suggest any approach.

 

Thanks in advance

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@sarthaks  you can use the following measures which works with or without any relationship

 

_origin =
CALCULATE (
    MAX ( Location[locationName] ),
    TREATAS ( VALUES ( Cargo[origin] ), Location[locationID] )
)

_destination =
CALCULATE (
    MAX ( Location[locationName] ),
    TREATAS ( VALUES ( Cargo[destination] ), Location[locationID] )
)

 

 

smpa01_0-1635130801309.png

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@sarthaks  you can use the following measures which works with or without any relationship

 

_origin =
CALCULATE (
    MAX ( Location[locationName] ),
    TREATAS ( VALUES ( Cargo[origin] ), Location[locationID] )
)

_destination =
CALCULATE (
    MAX ( Location[locationName] ),
    TREATAS ( VALUES ( Cargo[destination] ), Location[locationID] )
)

 

 

smpa01_0-1635130801309.png

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Thanks! @smpa01 your solution worked for me.

CNENFRNL
Community Champion
Community Champion

To my understanding, LOOKUPVALUE is a legacy from Excel. Here's use a more PBI way to deal with it, which involves inactive relationship and expanded table,

Screenshot 2021-10-24 081430.png

 

Name Org = CALCULATE(MAX(LOC[LocationName]), CARGO)
Name Dest =
CALCULATE(
    MAX( LOC[LocationName] ),
    CALCULATETABLE(
        CARGO,
        USERELATIONSHIP ( CARGO[Destination], LOC[LocationID] )
    )
)

 

Screenshot 2021-10-24 081726.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jos_Woolley
Solution Sage
Solution Sage

Hi,

Not sure what you mean when you say "Requirement is to replace the Origin and Destination columns...". You can't overwrite data or remove columns with DAX.

You can add two additional columns to your Cargo table, e.g.:

Origin Location =
LOOKUPVALUE ( Location[LocationName], Location[LocationID], Cargo[Origin] )

A similar construction could be used to derive the Destination Location.

Regards

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors