Sales Data |
Data Model |
Retrieving a Value from the Same Table
Sometimes, you need to retrieve a value from a specific row in the table you're already in. This is one of the great use cases for LOOKUPVALUE(). For our scenario, we want to compare the Sales for each row in the Sales table to the Sales for January for that same customer. Let's see how it's done.
January Sales (Formula) |
January Sales (Results) |
Retrieving a Value From Up the Hierarchy
Now, what if we wanted to retrieve a specific value from the lookup table. In our case, let's say that we want to pull Customer Type down into the Sales table. We could use LOOKUPVALUE() to accomplish this as well. However, there's a far simpler way, the RELATED() function. The RELATED() function uses Row Context to retrieve a value from up the hierarchy.
Customer Type |
Retrieving a Value From Down the Hierarchy
Now, what if we wanted to pull a value from the transaction table into the lookup table. Ordinarily, this is done using aggregations and the CALCULATE() function. However, in some cases, you want to retrieve a specific value with no aggregation. Let's try pulling the Sales for February up into the Customers table.
February Sales |
Retrieving a Value from an Unrelated Table
We tried our best to find an example of this that works in a useful. Simply put, this is VERY sticky territory. DAX is built around utilizing relationships. Therefore, it can become quite difficult to work without relationships. To summarize, if you are trying to connect two tables without some type of relationship chain, you may want to reconsider your modelling. If anyone in the comments can find a good example, let us know!
Hopefully, this post opened up your mind to the possibilities of using LOOKUPVALUE(). It's not a unique function by any means, but it sure is easy and intuitive to use. That's worth quite a bit in our book. Thanks for reading. We hope you found this informative.
Brad Llewellyn
BI Engineer
Valorem Consulting
@BreakingBI
www.linkedin.com/in/bradllewellyn
llewellyn.wb@gmail.com
Hello
ReplyDeleteThe biggest disappointments in our lives are often the result of misplaced expectations. This is especially true when it comes to our relationships and interactions with others.Read more-Sex and Relationship Advice For Women
It opened my mind, amazing usage! Thank you so much for the great job!
ReplyDeleteGreat post. Thanks for sharing
ReplyDeleteIf there are two fields in the same table which can be classified in the same context e.g. eye colour and hair colour may be classified using the 'colours' table.
ReplyDeleteAlthough I haven't tried the Lookupvalue function yet, I use an unrelated date table in my model because I have lots of dates in my tables and that would require building several relationships and switching between them to do my calculations. That is why I choose to use Calculate and filter dates as [date field] <= MIN(Calendar(Date)), for example. And it works fine FAIK.
ReplyDeletethanks for your post.