Hello, I would appreciate any help on this one, I'm trying to achieve this in a beast mode to maintain speed.
I have a data set,
Order_date | Item _ID | Order_id | Source | Addon |
Date | 1 | O_1 | site 1 | addon 1
Date | 1 | O_1 | site 1 | addon 2
Date | 2 | O_2 | site 1 | addon 1
Date | 3 | O_3 | site 1 |
I can output this in a table fine to show the correct count of each addon, but I need to show what % each addon is split by source of the total count of item_id. The problem is total count would count each item_id for every addon within that same order. I need to count all unique item_ids to get the total orders, then use the count of the addon to create the % of.
My thinking was an over window function may be able to achieve this by getting the total of all orders first to use to calculate the %, but not having any joy as this will not include any orders that did not have addons.
SUM(
COUNT(DISTINCT `item_id`)
) OVER( PARTITION BY `source` )
The desired output would be in a pivot table with Source as a column
Addon | % of Total
Addon 1 | 50%
Addon 2 | 25%
Any ideas to solve this problem is greatly appreciated. Apologies if this is unclear but any questions I will try my best to elaborate.
Thanks