DAX 中包含 distinct 的 LEFT JOIN 子查询的等价物
Equivalent of LEFT JOIN subquery containing distinct in DAX
我有以下查询:
SELECT d.department
,COUNT(*)
FROM fact_table AS f
LEFT JOIN
(SELECT DISTINCT sk_dept, department FROM dim_department ) AS d ON d.sk_dept=f.fk_dept
WHERE f.employee_status <> 2
GROUP BY d.department
这是查询的输出:
Department Count
1 250
2 300
部门维度如下:
DepartmentSK DepartmentId SubDepartment
1 1 23
2 1 67
3 1 120
4 2 44
该部门有子部门我的措施显示重复:
Employee Count By Dept =
CALCULATE (
DISTINCTCOUNT( fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
我们如何在 DAX 度量中包含包含 distinct 的 LEFT JOIN 子查询?
我用 DAX 公式得到的输出:
Department Count
1 500
2 600
由于deptid存在很多次,因为每个部门都有很多子部门,因此计数重复。
尝试使用 DISTINCT 求和以获得部门的唯一值:
Employee Count By Dept =
SUMX (
DISTINCT(VALUES(dim_department[department])),
CALCULATE (
DISTINCTCOUNT(fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
)
)
我有以下查询:
SELECT d.department
,COUNT(*)
FROM fact_table AS f
LEFT JOIN
(SELECT DISTINCT sk_dept, department FROM dim_department ) AS d ON d.sk_dept=f.fk_dept
WHERE f.employee_status <> 2
GROUP BY d.department
这是查询的输出:
Department Count
1 250
2 300
部门维度如下:
DepartmentSK DepartmentId SubDepartment
1 1 23
2 1 67
3 1 120
4 2 44
该部门有子部门我的措施显示重复:
Employee Count By Dept =
CALCULATE (
DISTINCTCOUNT( fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
我们如何在 DAX 度量中包含包含 distinct 的 LEFT JOIN 子查询?
我用 DAX 公式得到的输出:
Department Count
1 500
2 600
由于deptid存在很多次,因为每个部门都有很多子部门,因此计数重复。
尝试使用 DISTINCT 求和以获得部门的唯一值:
Employee Count By Dept =
SUMX (
DISTINCT(VALUES(dim_department[department])),
CALCULATE (
DISTINCTCOUNT(fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
)
)