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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Hussain_R
Frequent Visitor

Return Value from another table[column] based on weight

I have a table where I want to lookup a value from another table, but I want to lookup the value that I want to pick has a weight and it needs to return the value with the highest weight behind it.

Customer Table

Cust_IDNameLookup Value
0001221Anam 
0002022Megan 
0031003Rania 
0010019Karim 

 

Fact Table

DateCust_IDProd_IDSpend
1/1/220001221K.00112
1/3/220002022K.00212
12/2/220031003K.00324
13/2/220010019K.00136
14/4/220001221K.00242
13/3/220002022K.00431

 

Product Table:

Prod_IDProd_NameCate
K.001Credit Card1
K.002Auto Loan3
K.003Home Loan4
K.004Edu Loan2

 

Edit: Need a solution that is in DAX as using PQ takes ages for PBI to apply changes.

I want to lookup the value of product ID from fact table in the customer table but which has the highest cate from the product table.

 

So for example, the highest product ID for Anam will be K.002 even though she has spent on credit card.

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @Hussain_R ,

 

Please new a calculated column in Customer Table:

Lookup Value =
VAR _cust_id = 'Customer'[Cust_ID]
VAR _table =
    CALCULATETABLE ( VALUES ( 'Fact'[Prod_ID] ), 'Fact'[Cust_ID] = _cust_id )
VAR _max_cate =
    CALCULATE ( MAX ( 'Product'[Cate] ), 'Product'[Prod_ID] IN _table )
VAR _prod_id =
    CALCULATE ( MAX ( 'Product'[Prod_ID] ), 'Product'[Cate] = _max_cate )
RETURN
    _prod_id

vcgaomsft_0-1665988195442.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

6 REPLIES 6
v-cgao-msft
Community Support
Community Support

Hi @Hussain_R ,

 

Please new a calculated column in Customer Table:

Lookup Value =
VAR _cust_id = 'Customer'[Cust_ID]
VAR _table =
    CALCULATETABLE ( VALUES ( 'Fact'[Prod_ID] ), 'Fact'[Cust_ID] = _cust_id )
VAR _max_cate =
    CALCULATE ( MAX ( 'Product'[Cate] ), 'Product'[Prod_ID] IN _table )
VAR _prod_id =
    CALCULATE ( MAX ( 'Product'[Prod_ID] ), 'Product'[Cate] = _max_cate )
RETURN
    _prod_id

vcgaomsft_0-1665988195442.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

This works, but when trying to report the count of customers as a matrix/table with area as rows and columns as the product ID, I can't get the unique counts per area. I get the total customer's I have in the list who're subscribed to the products in each cell and not the unique counts pertaining to said area under specific product ID's. 

 

AreaK.001K.002K.003K.004
North12  
South  1 
East  3 
West   3

 

The purpose of the above visual is to show area's highest product subscribed by subscribed customer's, which can also be filtered via a slicer. What it currently shows is the total number of subcribing customer's. 

 

Edit: The highest K.003 has 84 customer's subscribed to said product. Currently, selecting ID K.003 as a slicer filter, it only shows 2 counts for each area whereas 60% came from the north, and the balance came from west. 

Hi @Hussain_R ,

 

this is off the topic of the thread. please consider ending this thread and reopening a new one. thanks.

 

Best Regards,
Gao

Community Support Team

Anonymous
Not applicable

Hi Hussain,

 

Please find the code

JamesFr06_0-1665857063369.png

lkup =
var __step1=calculate(max('Fact'[Prod_ID]),ALLEXCEPT(Customer,Customer[Cust_ID]))
var result= calculate(max('Product'[Cate]),'Product'[Prod_ID]=__step1)
return
result

Wouldn't I be comparing the text data with integer as the product ID is type text and PBI throw an error?

 

Edit: It does. It says:

 

DAX comparison operations do not support comparing values of type Integer with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values

Anonymous
Not applicable

It sent me no error. I builyt a file with your datas and it works

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.