Hi there,
If we keep your table setup as is, if you create appropriate relationships between the tables, you can use those relationships to perform the "lookup".
I have uploaded an example in
Excel &
Power BI Desktop.
I have renamed your tables just to make each table's purpose clearer:
Table 1 =>
Sales
Table 2 =>
Price
Table 3 =>
Customer
Table 4 =>
Calendar
Additional tables I added:
Product &
Quarter
Relationships required:
- Sales[Month] - Calendar[Month]
- Sales[Customer ID] - Customer[Customer ID]
- Sales[Product ID] - Product[Product ID]
- Price[Quarter] - Quarter[Quarter]
- Price[Customer ID] - Customer[Customer ID]
- Price[Product ID] - Product[Product ID]
- Calendar[Quarter] - Quarter[Quarter]
First define Sales Volume:
Code:
[B]Sales Volume[/B] =
SUM ( Sales[Volume] )
For Sales Amount, well, there are two ways I can think of to write it, either by iterating over Sales (summarized) or iterating over Price:
Code:
[B]Sales Amount Iterate Sales[/B] =
SUMX (
SUMMARIZE (
Sales,
Quarter[Quarter],
Customer[Customer ID],
'Product'[Product ID]
),
[Sales Volume] * CALCULATE( VALUES ( Price[Price] ) )
)
[B]Sales Amount Iterate Price[/B] =
SUMX (
Price,
[Sales Volume] * Price[Price]
)
The "lookup" happens due to the CALCULATE function being called within the row context of the SUMMARIZEd Sales table or Price, which adds the row context to the filter context. If you are iterating SUMMARIZE(Sales...), all of the columns filter Price. If you are iterating Price, the extended Price table (following all relationships from the Price table in the many-one direction) filters Sales.
Then Average Price if you want it is simply:
Code:
[B]
Average Price[/B] =
DIVIDE ( [Sales Amount [I]whichever version[/I]], [Sales Volume] )
One change I would suggest is changing the Price table to Monthly instead of Quarterly (at the data load stage). This would allow you to get rid of the pesky Quarter table. Also, you might want to use a regular Date table instead of the monthly one (if it makes sense).
You could also pre-compute Sales Amount in the Sales table using Power Query.
Owen