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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Sujit_Nayak
New Member

Aggregation of values from a different table based on filters on multiple tables

Hi,

I'm looking for some help to solve a problem I have:

 

I have a table of Materials and their components and another table with Component Materials and their Prices:
ProductComp:

Material IDComponent Material ID
76386556
76364626
7632692
7632702
7632703
7632713
7632714
7632715
7632720

 

CompPrice:

Material IDPriceStart DateEnd Date
865565.0001-Oct-202331-Dec-2023
865565.5001-Jan-2024 
6462623.4301-Oct-202331-Dec-2023
6462623.8701-Jan-2024 
26921.5601-Oct-202331-Dec-2023
26922.2001-Jan-2024 
2702150.0001-Oct-202331-Dec-2023
2702156.0001-Jan-2024 
270340.2501-Oct-202331-Dec-2023
270340.2901-Jan-2024 
27130.4501-Oct-202331-Dec-2023
27130.5601-Jan-2024 
271412.0001-Oct-202331-Dec-2023
271413.0001-Jan-2024 
27155.0001-Oct-202331-Dec-2023
27155.4601-Jan-2024 
27201.4501-Oct-202331-Dec-2023
27201.4801-Jan-2024 

 

I then have a table of Inventory. I need to add a column to this table to have the sum of prices of components of the Material ID of the Inventory.

 

Inventory:

Inventory IDMaterial IDActive DateSUM of price
10000176301-Jan-2024?

 

Any help will be greatly appreciated, please.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Sujit_Nayak 

 

 

Please try this:

Delete all the relationships between the tables:

vzhengdxumsft_1-1721704618312.png

Then add a calculated column in the Inventory table:

Column =
	VAR _vtable = FILTER(
		CROSSJOIN(
			'CompPrice',
			'ProductComp'
		),
		'CompPrice'[Material ID] = 'ProductComp'[Component Material ID]
	)
	RETURN
		SUMX(
			FILTER(
				_vtable,
				'ProductComp'[Material ID] = 'Inventory'[Material ID] && 'CompPrice'[Start Date] <= 'Inventory'[Active Date] && 'Inventory'[Active Date] <= 'CompPrice'[End Date]
			),
			[Price]
		)

Given your CompPrice table is missing some End Date data, I haven't get the target result.

vzhengdxumsft_0-1721704551767.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Assuming there will never be repetitions in the Material column of the CompPrice table, create a relatiopnshipe (Many to One and Single) from the ProductComp table to the CompPrice table.  Write a RELATED() function int the ProductComp table to bring over the Price from the PriceComp table.  In your visual, you should now be able to write this simple measure

T = sum(ProductComp[Price])


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur You caught me out there :). The CompPrice table indeed has repetitions (I left it out for simplicity, but I guess it is pertinent). The Prices for a Material ID are for a date range - start and end dates. So a material ID does repeat for different prices for different applicable date ranges.

The price to lookup from CompPrice table for an Inventory is based on the condition where a Date field (Active date) from the Inventory table is within the date range for each of its components.
I've updated the table schema to reflect this. 
Also, I'd like to add the sum as a new column to the Inventory table and not a measure in a visual, please.

Hi,

Show the result you are expecting and also justfy why do you want a calculated column formula (why not a measure?)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
PhilipTreacy
Super User
Super User

Hi @Sujit_Nayak 

 

Download example PBIX file

 

Create the 3 tables and create relationships like so, each table is linked on the Material ID.

 

rels.png

 

You can then display the Inventory table with the 3rd column being the Price from the CompPrice table.  Choose the aggregation Sum for this column.

 

sumprice.png

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy : Thanks for the response. But please see my reply to @Ashish_Mathur . I guess you too assumed the one to many relationship from CompPrice to ProductComp ? Also I missed out mentioning the condition to retrieve the price based on a date creiteria from the Inventory table to match the correct date range from the CompPrice table. I've updated the original post with these details. Apologies for the confusion.

Anonymous
Not applicable

Hi @Sujit_Nayak 

 

 

Please try this:

Delete all the relationships between the tables:

vzhengdxumsft_1-1721704618312.png

Then add a calculated column in the Inventory table:

Column =
	VAR _vtable = FILTER(
		CROSSJOIN(
			'CompPrice',
			'ProductComp'
		),
		'CompPrice'[Material ID] = 'ProductComp'[Component Material ID]
	)
	RETURN
		SUMX(
			FILTER(
				_vtable,
				'ProductComp'[Material ID] = 'Inventory'[Material ID] && 'CompPrice'[Start Date] <= 'Inventory'[Active Date] && 'Inventory'[Active Date] <= 'CompPrice'[End Date]
			),
			[Price]
		)

Given your CompPrice table is missing some End Date data, I haven't get the target result.

vzhengdxumsft_0-1721704551767.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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