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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Saxon10
Post Prodigy
Post Prodigy

Lookup using measure and dax from one table to another table

I have 3 tables are Data, Report and Priority.

 

In Data table contains duplicate items with unique code and qty, report table contain unique item only and Priority table contain order for the code.

In data table the same item has two different codes are "CHE" and "RCB" so I would like to pull the code and qty against code "CHE" only that's my first priority and there is no "CHE" then pick from "RCB" that's secound priority.

In data table the items has duplicate with code so I created two different columns in data table (count, Unique count) to get the unique count for code against the items.

CODE ORDER =
VAR CODE_ORDER = DATA[CODE]
RETURN
LOOKUPVALUE(PRIORITY[ORDER],PRIORITY[CODE],CODE_ORDER)
CODE ORDER UNIQUE COUNT =
VAR CODE_ORDER = DATA[CODE ORDER]
RETURN
IF(CODE_ORDER = CALCULATE(MIN(DATA[CODE ORDER]),ALLEXCEPT(DATA,DATA[ITEM])),1,0)

and finally I used lookupvalue function to bring the code and qty against the item in report table by using below mentioned formula

CODE = LOOKUPVALUE(DATA[CODE],DATA[ITEM],REPORT[ITEM],DATA[CODE ORDER UNIQUE COUNT],1)
QTY = LOOKUPVALUE(DATA[QTY],DATA[ITEM],REPORT[ITEM],DATA[CODE ORDER UNIQUE COUNT],1)

Question:
 
1. I want to get the same result by using DAX New calculated column option without duplication in data table (Count and unique count column in data table- Creating DAX from data table into report table without priority table).
2. I want to get the same result by using Measure option without duplication in data table (Count and unique count column in data table- Creating Measure from data table into report table without priority table).
 
 

DM1.PNGDT3.PNGRT2.PNGPT4.JPG

Link here for PBI file https://www.dropbox.com/s/9xoyhnqthp5td3y/LOOKUPVALUR-MES%26CAL-28-07-22.pbix?dl=0 

5 REPLIES 5
lbendlin
Super User
Super User

Power BI likes data models in star or snowflake format.  Dimensions on the outside, facts in the middle.  Your tables are a mix of facts and dimensions. I would recommend you rethink and refactor your data model to separate dimensions from facts. 

 

LOOKUPVALUE  is something you use between unrelated tables. In a good data model you don't need to use that, let the data model do the work for you. Worst case use TREATAS.

@lbendlin,

 

Thanks for your reply. 

 

Can I get a measure for similar to the calculate column logic. I am trying to bring it column in measure but its supporting. 

That's the raw data so its difficult to change the date but I try it. 

 

 

attached is a cleaned up version. It does not require any LOOKUPVALUE.  Technically the code order table is not required either as the codes are already sorted alphabetically.

@lbendlin,

 

Thanks for your reply and solution and I am aware of the options. 

 

I want the same result within the same same column by using DAX code(New calculate column and measure) without duplication column in data table. 

I am currently achieving the result by using lookvalue function with adding the support columns in data table. I am trying to avoid the option and looking for alternative solutions. 

Thank you. 

 

"I want the same result within the same same column "

 

Can't help you with that. I think it's not a good design. Maybe someone else can chime in.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.