我正在尝试将我在TSQL中编写的查询转换为DAX,并且很难确定如何在DAX中使用子查询。 这是我的源代码SQL代码:
Select [DayOfWeekNumber], [DayOfWeek], Ratio=Avg (100*Opened/ Sent) From
(select [DayOfWeekNumber], [DayOfWeek], e.Schedule_ID
, Count (e.opened) as Opened
, Sum (e.NoOfEmailSent) as Sent
from
Events e
join dim_date D on d.ID_Date = e.ID_Date
where
e.AccountNumber = 1
group by d.[DayOfWeek], [DayOfWeekNumber], e.Schedule_ID
having
Sum (e.NoOfEmailSent) > Count (e.opened)
) OBSHour
group by [DayOfWeekNumber], [DayOfWeek]
Order by [DayOfWeekNumber]
此查询的目的是计算打开的电子邮件数量与首先计算每个电子邮件时间表和工作日的已打开/已发送电子邮件数量的开放比率,然后计算同一工作日所有比率的平均值。 例如,如果星期日的数据是这样的:
Schedule_ID Open Sent Ratio
123 10 100 .1
125 2 10 .2
129 1 4 .25
然后星期日的最终比率将变为(.1 + .2 + .25)/3=.18
感谢您的帮助。