Our spice dataset is organized by transactions. I need to calculate the total count of transactions each week / the total number of distinct customers for all time (subject to filters like {region} etc. If I do something like:distinct_count({transaction_id)) / distinct_count({customer_id}) and then plot it on a chart by week, the denominator becomes the count of customers who had a transaction that week, not all customers across time.
I can get total customers across the time period with a formula like: distinctCountOver({customer_id},[{cust_constant}], PRE_AGG), but if I try: distinct_count({transaction_id)) / distinctCountOver({customer_id},[{cust_constant}], PRE_AGG) I get error âmismatched aggregation.â
Given a filtered group of transactions over a time period, how can I get the total customers across the time period as a denominator?
Really what I am doing here is trying get the partition field from your distinct count over function into this ifelse statement but depening on the value it may not work.
Thank you for the response. Actually, {cust_constant} is a hack. Itâs a calculated field attached to every record whose value is simply âfooâ. In order to count distinct customers PRE-AGG I have to have a grouping field. QS wonât let me distinctCountOver({customer_id}, PRE-AGG).
My challenge is getting the total count of all customers who purchased over a year and using that value as the denominator for sales per [all] customer each week.
If I aggregate a chart by week, QS seems to automatically aggregate my customers to only those who made a transaction that week. I need something like âdistinct sales per week divided by total distinct customers that yearâ
I didnât realize I could group by â[ ]â so I got rid of the useless {cust_constant}.
My real issue was a mismatched aggregation because I needed a distinct_countIf for the transactions (to get specified ones), but I needed to divide by the distinctCountOver for the customers to get all across the whole time period.
Fix was to min(distinctCountOver(âŚ)
The final calc that works is distinct_countIf({transaction_id}, {if expression}) / min(distinctCountOver({customer_id},[],PRE_AGG))