Forum Discussion
Imrageth
Oct 26, 2023Copper Contributor
Issue with an average based on a specific filter
Hi, Below is a simple represantion of the structure I'm dealing with. I want to find out average order value for apple, pears, etc but make sure it include other products in the average. O...
Lorenzo
Oct 26, 2023Silver Contributor
Hi Imrageth
With data formated as Table (not mandatory but recommended) named TableOrder:
in F2:
=LET(
StackAvg, LAMBDA(seed,product,
LET(
orders, FILTER(TableOrder[ORDER ID], TableOrder[PRODUCT]=product),
also, IFNA(XMATCH(TableOrder[ORDER ID],orders),0),
scope, FILTER(TableOrder[[QNT]:[PRICE]], also),
VSTACK(seed, ROUND(SUMPRODUCT(CHOOSECOLS(scope,1), CHOOSECOLS(scope,2)) / COUNT(UNIQUE(orders)),2))
)
),
Products, SORT(UNIQUE(TableOrder[PRODUCT])),
Averages, REDUCE("AVERAGE",Products, StackAvg),
HSTACK(VSTACK("PRODUCT",Products), Averages)
)