首页 文章

DAX - 使用多个过滤器在线级别(SUMX)进行计算

提问于
浏览
0

我想让DAX做的是:

  • 查看HR数据表中的每一行 .

  • 确定员工的开始日期("employee a")

  • 使用以下过滤器总结表中其他员工的数量:
    一个 . 成功完成了作业
    湾在开始日期之前结束他们的任务31
    C . 在开始日期之后结束他们的任务 - 31(也就是说在员工开始日期的一个月内)
    d . 在员工a之前开始(不计算员工a或其计算中的任何人)
    即与员工a具有相同的职称 .

这基本上是用普通英语提问“对于我的每个员工,有多少其他具有相同职位的员工在该员工开始的一个月内成功结束了他们的任务?”在DAX中基本上只是“如何将多个过滤条件应用于SUMX或COUNTAX度量/计算列?”

我已经尝试过的措施是:

Contractors Available = COUNTAX(
'BAT VwRptMspAssignment',
    CALCULATE(
        DISTINCTCOUNT('BAT VwRptMspAssignment'[assignmentgk]),
        FILTER(
            FILTER(
                FILTER(
                    FILTER(
                        FILTER(ALL('BAT VwRptMspAssignment'),
                        'BAT VwRptMspAssignment'[End.Date]<EARLIER('BAT VwRptMspAssignment'[Start.Date])+31),
                    'BAT VwRptMspAssignment'[End.Date]>EARLIER('BAT VwRptMspAssignment'[Start.Date])-31),
                'BAT VwRptMspAssignment'[Start.Date]<EARLIER('BAT VwRptMspAssignment'[Start.Date])),
            'BAT VwRptMspAssignment'[EoaReason]="Successful Completion"),
        'BAT VwRptMspAssignment'[JobPostingTitle.1]=EARLIER('BAT VwRptMspAssignment'[JobPostingTitle.1]))
        )
    )

我尝试的计算列是:

Contractors Available.1 = SUMX(
FILTER(
        FILTER(
            FILTER(
                FILTER(
                    FILTER(
                        FILTER(ALL('BAT VwRptMspAssignment'),
                            'BAT VwRptMspAssignment'[customergk]=EARLIER('BAT VwRptMspAssignment'[customergk])),
                        'BAT VwRptMspAssignment'[JobPostingTitle.1]=EARLIER('BAT VwRptMspAssignment'[JobPostingTitle.1])),
                        'BAT VwRptMspAssignment'[End.Date]<EARLIER('BAT VwRptMspAssignment'[Start.Date])+31),
                    'BAT VwRptMspAssignment'[End.Date]>EARLIER('BAT VwRptMspAssignment'[Start.Date])-31),
                'BAT VwRptMspAssignment'[Start.Date]<EARLIER('BAT VwRptMspAssignment'[Start.Date])),
            'BAT VwRptMspAssignment'[EoaReason]="Successful Completion"),

'BAT VwRptMspAssignment'[FinishFlag])

但这些解决方案都没有奏效 .
有谁知道为什么或我还能尝试做些什么呢?导出到Excel的数据格式示例:

scrubbed data

"Contractors Available.2"是计算列 . 注意第一行中的521 . 如果我在Excel中应用所有这些过滤器,它应该为零,此作业 Headers 在数据集中是唯一的 . 它表示107 "Technical Writer - Expert"行应在2009年9月26日的一个月内结束,但这些是数据集中仅有的3位技术作者,其他两位中的零在2016年9月30日的一个月内结束了他们的作业:
enter image description here

1 回答

  • 1

    尝试这样的计算列:

    Contractors Available.1 =
    VAR StartDate = 'BAT VwRptMspAssignment'[Start.Date]
    VAR JobTitle = 'BAT VwRptMspAssignment'[JobPostingTitle.1]
    RETURN
        COUNTROWS (
            FILTER (
                'BAT VwRptMspAssignment',
                'BAT VwRptMspAssignment'[End.Date] < StartDate + 31
                    && 'BAT VwRptMspAssignment'[End.Date] > StartDate - 31
                    && 'BAT VwRptMspAssignment'[Start.Date] < StartDate
                    && 'BAT VwRptMspAssignment'[EoaReason] = "Successful Completion"
                    && 'BAT VwRptMspAssignment'[JobPostingTitle.1] = JobTitle
            )
        )
    

    EARLIER函数不是必需的,因为变量将保持定义它们的上下文,即rowcontext .

    EDIT: 我用你提供的数据测试了我的公式,它似乎有效 . 我更改了第二行的[End.Date],以获得第一行的结果 .

    enter image description here

相关问题