简体   繁体   English

通过SQL'WHERE IN'类型限制仅对一个值进行PowerPivot / DAX度量

[英]PowerPivot/DAX measure with SQL 'WHERE IN'-type restriction on just one one value

I am reporting on course completions by site, using a very simple DataModel: 我正在使用非常简单的DataModel按站点报告课程完成情况:

在此处输入图片说明

This gives me a PivotTable that looks the one shown right below: 这给了我一个数据透视表,看起来如下图所示:

在此处输入图片说明

A complication I'm dealing with is that I only want to report percentages for the Course1 module based on people with the job titles found in the Course1 Audience table shown to the left of the PivotTable. 我要处理的一个复杂问题是,我只想根据数据透视表左侧显示的Course1 Audience表中具有职位的人员来报告Course1模块的百分比。 Currently I'm achieving this by hard-coding those job titles into my measure like so: 目前,我正在通过将这些职位硬编码到我的方法中来实现此目标,如下所示:

IF(HASONEVALUE(Completions[Module]),
    IF(VALUES(Completions[Module])="Course1",
        CALCULATE(COUNTA(Completions[Email]),
            OrgChart[Title]="Job Title 1"
            ||OrgChart[Title]="Job Title 2"
            ||OrgChart[Title]="Job Title 3"
            ||OrgChart[Title]="Job Title 4"
            ||OrgChart[Title]="Job Title 5")
         /CALCULATE(COUNTA(AllStaff[Email]),
            OrgChart[Title]="Job Title 1"
            ||OrgChart[Title]="Job Title 2"
            ||OrgChart[Title]="Job Title 3"
            ||OrgChart[Title]="Job Title 4"
            ||OrgChart[Title]="Job Title 5"))
    ,COUNTA(Completions[Email])/COUNTA(AllStaff[Email]))
,BLANK())

While that works just fine, it's rather unwieldy and I just hate hard-coding logic into a measure like that. 虽然这很好用,但相当笨拙,我讨厌将逻辑硬编码成这样的量度。 I'd much rather have the measure suck those Titles for Course1 from the Table, so that end users can amend this list without having to understand how to write DAX measures. 我宁愿让该度量从表中吸取Course1的那些标题,以便最终用户可以修改此列表,而不必了解如何编写DAX度量。

Is there any way I can instead reference the "Course 1 Audience" Table in my measure instead of these bits?: 有什么方法可以代替这些位数来代替我在自己的度量中引用“课程1受众”表?

OrgChart[Title]="Job Title 1"
||OrgChart[Title]="Job Title 2"
||OrgChart[Title]="Job Title 3"
||OrgChart[Title]="Job Title 4"
||OrgChart[Title]="Job Title 5"

Note that this only applies to Course1. 请注意,这仅适用于Course1。 The completion rates of all other courses should be calculated based on ALL staff, and NOT excluded to just those job titles in the Course 1 Audience table. 所有其他课程的完成率应基于所有员工来计算,并且不仅仅限于“课程1受众”表中的那些职位。

You can use the CONTAINS() function. 您可以使用CONTAINS()函数。 This little snippet should work, though I don't have your dat so I can't test it out. 这个小片段应该可以用,尽管我没有您的数据,所以我无法对其进行测试。 Make sure your Course 1 Audience data is stored in your data model as well. 确保您的“课程1受众”数据也存储在数据模型中。

FILTER(OrgChart,CONTAINS(VALUES([Course 1 Audience]),[Course 1 Audience],OrgChart[Title])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM