简体   繁体   English

基于两个过滤器的单个表上的单个非重复计数度量-每个过滤器值位于单个表的不同行上

[英]Single distinct count measure on a single table based on two filters - each filter value on distinct rows of the single table

I'm trying to demo some more complex DAX / powerpivot concepts to people on my team. 我正在尝试向团队成员演示一些更复杂的DAX / powerpivot概念。 I came up with an example to walk them through, but I think might actually be impossible. 我想出了一个例子来指导他们,但我认为实际上可能是不可能的。

Happy to change the example to something else, but this has really piqued my interest. 很高兴将示例更改为其他内容,但这确实激起了我的兴趣。 Does anyone know how to do it? 有人知道怎么做吗?

Here's some example data, single table, nothing fancy... 这是一些示例数据,单个表,没什么花哨的……

    Child ID | Type      | Parent ID
    1        | A         | 1
    1        | A         | 2
    1        | B         | 3
    1        | C         | 4
    2        | B         | 436
    2        | B         | 983
    2        | A         | 24
    2        | A         | 444
    3        | A         | 67
    3        | A         | 67
    3        | B         | 4
    3        | B         | 3

What I'd like to do is - per Child ID, Distinct Count Parent IDs of Type A which have a Parent ID of 4 attributed to it somewhere... in a single measure... 我想做的是-针对每个孩子ID,在某处将A的父ID归因于类型A的非重复计数父ID(以单个度量)...

So the result in a pivot would be.... 因此,枢轴的结果将是...。

    Child ID | DCnt_PiD
    1        | 2
    2        | 0
    3        | 1

I have played around with this in a DAX query editor, trying crossjoins, generates mixed with addcolumns etc. but they didn't work (cannot join a table with the same column id etc.)... 我已经在DAX查询编辑器中进行了尝试,尝试进行交叉联接,生成与addcolumns混合的等,但是它们不起作用(无法联接具有相同列ID的表等)。

The measure would then relate over to another table via a bridge table, so can't use a pivot I'm afraid... 然后,该度量将通过桥表关联到另一个表,因此恐怕不能使用枢轴...

Anyone got any ideas? 任何人有任何想法吗?

Cheers 干杯

Cracked it in a DAX Query, now time to turn it into a measure! 在DAX查询中破解了它,现在该把它变成度量了!

EVALUATE
 (
    SUMMARIZE (
        FILTER (
            SUMMARIZE (
                table,
                table[Child_ID],
                table[Type],
                table[Parent_ID]
            ),
            table[Type] <> "B"
                && table[Type] <> "C"
                && CALCULATE (
                    COUNTROWS ( table ),
                    ALLEXCEPT ( table, table[Parent_ID], table[Child_ID] ),
                    table[Parent_ID] = 4
                )
                    > 0
        ),
        table[Child_ID],
        "DCnt_Pid", DISTINCTCOUNT ( table[Parent_ID] )
    )
)
ORDER BY [Child_ID]

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

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