Forum Discussion
Average Selling Price - Criteria from Multiple Columns
I need to calculate the average selling price of an item in a Sales table. This would normally be as simple as creating a calculated column using:
DIVIDE(
SUM(Sales[SalesAmount]),
SUM(Sales[SalesQty])
) but my Sales table has additional data, for example the [CustomerID], [SalesRegion], and [SalesType]. I need to find the average selling price for each item identified by these features. For example, I need the average price for Item A purchased by Customer A in an Online Sale, which is different from Item A purchased by Customer A in an In-Store sale.
Originally, I used something like this:
ASP by Item =
VAR PriorYear = YEAR(Sales[Invoice Date]) - 1
VAR CurrentItem = RELATED(Item[ItemID])
VAR CurrentCustomer = RELATED(Customer[CustID])
RETURN
CALCULATE(
DIVIDE(SUM(Sales[SalesAmount]), SUM(Sales[SalesQty])),
FILTER(
Sales,
YEAR(Sales[Invoice Date]) = PriorYear
),
FILTER(
Sales,
RELATED(Item[ItemID]) = CurrentItem
),
FILTER(
Sales,
RELATED(Customer[CustID]) = CurrentCustomer
)
)My actual use case has more filters, and I end up running out of memory. My current solution is to use SUMMARIZECOLUMNS to make a table with the ASP, and then I created a key column by concatenating the relevant columns together in this table and my Sales table. This works, but the process is quite slow.
My Sales table has about 3M records, with he Customer and Item tables being in the tens of thousands of records range.
Is there a more efficient way to "roll up" an average by multiple columns?
7 Replies
- Ashish_Mathur
Super User
Hi,
DIVIDE(
SUM(Sales[SalesAmount]),
SUM(Sales[SalesQty])
)should be written as a measure (not as a calculated column)
- AnonymousNot applicable
For each sales transaction (i. e., row in Sales), I need the average selling price for a particular combination of item, customer, sales region, sales type, etc.. How would I construct a measure for this?
- Ashish_Mathur
Super User
Hi,
I do not understand. Share some data and show the expected result.
- v-juanli-msft
Community Support
Hi Anonymous
Is this problem sloved?
If not, please let me know.
If it is sloved, could you kindly accept useful method as a solution so that others may find the solution quickly?
Best Regards
Maggie