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
DataScope06
Helper I
Helper I

LookupValue matching multiple columns error

I am having issues finding the correct value when matching two text values between tables.

 

My data model has two tables. The first table is sales_items. The second table is returned_items. I want to match on the order_id and the sku columns. Then find the price for the returned items. The price is found in the sales_items table. There is also a quantity_returned column in the returned_items table. My goal is to add a column to the returned_items table with the price from the sales_items table for each returned sku. This must be matched by the order_id because a sku's price can fluctuate.

 

My issue: An order can have multiple sku's, but only one of those skus might be returned by the customer. But I am unable to get a correct match between the order_id AND the purchased-returned skus. There is an active relationship between the sales_items[order_id] and returned_items[order_id]. I have an inactive relationship between sales_items[sku] and returned_item[sku].

 

Using the below code with LOOKUPVALUE, I get an error that says, "A table of multiple values was supplied where a single value was expected."

 

 

 

Returns Sum = LOOKUPVALUE(sales_order_item[price],sales_item[order_id],'Returned_items'[order_id], sales_item[sku],'Returned_items'[sku])

 

 

 

When I use the below code with the CALCULATE function, then the price for the first sku for the matching order_id is returned, regardless if it matches the sku in the returned_items table.

 

 

 

Returns Sum2 = CALCULATE(
    max(
        sales_item[price])
        FILTER(sales_order_item,
        Sales_item[order_id] = Returned_items[order_id] &&
         sales_order_item[sku] = 'Returned_items'[sku]
        )
        
)

 

 

Here are example tables:

Sales_items

order_idskupriceQuantity_ordered
112310.001
112415.001
112510.001
22345.001
233520.001
312310.002
455525.003
422210.001

 

returned_items

order_idskuquantity_returned
11231
11241
23351
31231
45553
42221
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@DataScope06,

 

Here are two solutions. A relationship between the tables is not required.

 

1. Calculated column in table Returned_items:

 

Price = 
LOOKUPVALUE ( Sales_items[price], Sales_items[order_id], Returned_items[order_id], Sales_items[sku], Returned_items[sku] )

 

2. Calculated column in table Returned_items using a composite key. The composite key "order_id-sku" can be created in Power Query or DAX.

 

Price (composite key) = 
LOOKUPVALUE ( Sales_items[price], Sales_items[order_id-sku], Returned_items[order_id-sku] )

 

DataInsights_0-1674132508453.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@DataScope06,

 

Here are two solutions. A relationship between the tables is not required.

 

1. Calculated column in table Returned_items:

 

Price = 
LOOKUPVALUE ( Sales_items[price], Sales_items[order_id], Returned_items[order_id], Sales_items[sku], Returned_items[sku] )

 

2. Calculated column in table Returned_items using a composite key. The composite key "order_id-sku" can be created in Power Query or DAX.

 

Price (composite key) = 
LOOKUPVALUE ( Sales_items[price], Sales_items[order_id-sku], Returned_items[order_id-sku] )

 

DataInsights_0-1674132508453.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@DataInsights Your solution using LOOKUPVALUE ended up working. Which was the same function I had been trying to use. In my original post I had a typo that I went back and edited. The typo was just in this post though, not my workbook.

 

My real issue was my dataset did in fact have duplicate records. I was unaware that was possible in the database I pulled the data from. Hence the error stating, "A table of multiple values was supplied where a single value was expected."

Anyone who finds this question should verify their datasets do not have duplicate records if they see the table with multiple values error.

 

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.