我在 T-SQL 中有以下代码,它根据某些条件计算 [C-Services] 表的不同 [ClientID],并在多个字段上加入 [C_Episode] 表:
SELECT
cs.[ProgramName] AS [Program]
,COUNT(DISTINCT cs.[ClientID]) AS [# Clients Served]
FROM
[C_Services] cs
INNER JOIN [C_Episodes] epi ON (
(epi.[ProgramID] = cs.[ProgramID])
AND (epi.[ClientID] = cs.[ClientID])
AND (epi.[AdmissionDate] <= cs.[ServiceMonth])
AND (epi.[DischargeDate] >= cs.[ServiceMonth])
)
WHERE
(cs.[ClientID] > 0)
AND (cs.[IsNoShow] = 0)
AND (cs.[IsCancellation] = 0)
AND (cs.[IsNonClaimable] = 0)
GROUP BY
cs.[ProgramName]
此外,我也有与上述代码关联的 DAX Measure,但没有 INNER JOIN [C-Episodes] 表:
VAR countClients =
CALCULATE (
DISTINCTCOUNT ( 'C_Services'[ClientID] ),
FILTER (
'C_Services',
[ClientID] > 0
&& [Is Non-Claimable] = FALSE ()
&& [Is No-show] = FALSE ()
&& [Is Cancellation] = FALSE ()
)
)
RETURN
countClients
我的问题是 - 我必须如何修改 DAX 度量才能添加 INNER JOIN [C_Episodes] 表(在 T-SQL 代码中说明的三个条件下加入)?
我试图为第一个 JOIN ON ProgramID 列添加
NATURALINNERJOIN('C_Services'[ProgramID], 'C_Episodes'[ProgramID])
但它给出了一个错误 - “需要分组”,并且在我尝试将我的计算更改为 Summarize 或 Summarizecolumns 之后 - 它仍然给出了一个错误。