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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Handling duplicates when performing a calculation on numbers from two unrelated tables

Hi All!

 (Edited to add a OneDrive link to my pbix file. Apples and Crabapples pbix file )

 

First, I want to thank AIB for helping me with my original question on this topic, linked here: Performing a calculation on numbers from two unrelated tables . AIB’s solution worked great for the tables that I offered in my question.

 

I applied the solution to my actual data and wrestled with a “table of multiple values was supplied where a single value was expected” error for far too long. It turns out that I have lines with duplicate shop and type entries in one of my data tables. Of course, I cannot change how the data is given to me nor simply delete the duplicate lines.

 

I tried the solution using a column with a unique entry for each line using the shop and type entries plus a number indicating if that entry was a duplicate line and a column that summed all crabapple amounts for a specific shop. The “table of multiple values was supplied where a single value was expected” error went away but I can’t get the variable Crabapples_ to return anything but a blank.

 

Can anybody show me where I’m going wrong with this? I’ll try to attach a copy of my PowerBI file so you can see exactly what I’ve done once I get a useable One Drive account. 

 

Thanks so much!

 

Apples and Crabapples pbix file

 

Apples and Crabapples-All Stores.PNG

 

Apples and Crabapples-District.PNG

 

 

I can't figure out how to attach a copy of my PowerBI file so I'll copy the tables and the calculated columns I came up with.

 

New All Stores Data Set

StoreItemUnitsNew Units I'm looking forNotes:Store + ItemTrying to create New Units I'm Looking for columnWhat VAR Crabapples_ returns
UptownApples77No crabapples are from the Uptown store in the District data setUptown Apples7 
UptownStrawberries99 Uptown Strawberries9 
UptownGrapes44 Uptown Grapes4 
DowntownApples514 crabapples are from the Downtown store in the District data setDowntown Apples5 
DowntownBananas33 Downtown Bananas3 
DowntownPears1010 Downtown Pears10 
SuburbsApples743 crabapple is from the Suburb store in the District data setSuburbs Apples7 
SuburbsCantalopes66 Suburbs Cantalopes6 
SuburbsPineapple22 Suburbs Pineapple2 
RuralApples449 crabapples are from the Rural store in the District data set. Because this are more than the 4 apples in the All Stores data set the New Units number stays at 4.Rural Apples4 
RuralCantalopes11 Rural Cantalopes1 
RuralPineapple22 Rural Pineapple2 

 

New District Data Set

ShopTypeAmountShop + TypeIndexIncidence number for Shop + typeShop + Type + IncidenceAdding multiple Crabapple entries
UptownBananas7Uptown Bananas01Uptown Bananas7
UptownStrawberries9Uptown Strawberries11Uptown Strawberries9
UptownGrapes4Uptown Grapes21Uptown Grapes4
DowntownBananas5Downtown Bananas31Downtown Bananas5
DowntownCrabapples3Downtown Crabapples41Downtown Crabapples4
DowntownCrabapples1Downtown Crabapples52Downtown Crabapples 24
DowntownPears10Downtown Pears61Downtown Pears10
SuburbsCrabapples1Suburbs Crabapples71Suburbs Crabapples3
SuburbsCantalopes6Suburbs Cantalopes81Suburbs Cantalopes6
SuburbsPineapple2Suburbs Pineapple91Suburbs Pineapple2
SuburbsCrabapples2Suburbs Crabapples102Suburbs Crabapples 23
RuralCrabapples9Rural Crabapples111Rural Crabapples9
RuralCantalopes1Rural Cantalopes121Rural Cantalopes1
RuralPineapple2Rural Pineapple131Rural Pineapple2

 

Where the formula for the "Trying to create new Units I'm looking for column" calculated column is:

Trying to create New Units I'm looking for column =
IF (
'All Stores'[Item] <> "Apples",
'All Stores'[Units],
VAR Crabapples_ =
LOOKUPVALUE (
District[Adding multiple Crabapple entries],
District[Shop + Type + Incidence],'All Stores'[Store + Item],
District[Type], "Crabapples"
)
RETURN
IF ( Crabapples_ > 'All Stores'[Units], 'All Stores'[Units], 'All Stores'[Units] - Crabapples_)
)
3 REPLIES 3
amitchandak
Super User
Super User

I am not able to get you calculations correctly. In display data also overlapped.

 

This what we do to get data from another table. We use lookup of function like MINX, MAXX, SUMX , All X function

 

Eaxmple I want to get data in a new column of Table 1 from Table 2, I will try

new column= minx(filter(table2,table1[col1] =table2[col1] && table1[col2] =table2[col2]),table1[col4])

This can be a new column or part of new column calculation .

 

Hope this can help. In not. If possible please share a sample pbix file after removing sensitive information.Thanks.

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Anonymous
Not applicable

Hi Amitchandak,

 

Can you tell me how to share a pbix file? I didn't see an option to add files to my original post.

 

Thanks!

 

Hi @Anonymous ,

 

Please upload your files to One Drive and share the link here. Do mask your confidential information before that.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.