Hi
I have a Pivot table grouped by date (month) and name. I need to calculate the value of total distinct servers per month, which should be the same for each name within same month.
I have tried these formulas:
- sumOver(sum(distinct_count({server_id},[{event_date}])),[{event_date}])
- sumOver(sum(distinctCountOver({server_id},[{event_date}],PRE_AGG)),)
- sumOver(distinct_count({server_id}),[{event_date}])
but nothing works.
Note: Each server can relate to different names, thus it can be counted several times, one time per month name (Total Distinct Servers column).
In Total Distinct Servers per Month column same server should be counted just once, so in my example the number 7 should remain as is even when collapsing month rows to one row.
I can achieve the calculation (distinct_servers_by_month column) using this query:
select t.*,
p.distinct_servers_by_month
FROM table t join
(select date_trunc(‘month’,event_date) event_month,
count(distinct server_id) distinct_servers_by_month
from table
group by 1) p on date_trunc(‘month’,t.event_date) = event_month