首页 文章

基于切片器的动态桶

提问于
浏览
1

我有这张 table

usr box app device  bucket      bucket_box  bucket_app  bucket_box_app  month
u1  b1  a1  d1      > 3         3 devices   2 devices   2 devices       201809
u1  b1  a1  d2      > 3         3 devices   2 devices   2 devices       201809
u1  b1  a2  d3      > 3         3 devices   2 devices   1 device        201809
u1  b2  a2  d4      > 3         1 device    2 devices   1 device        201809
u2  b1  a1  d5      > 3         1 device    2 devices   1 device        201809
u2  b2  a3  d6      > 3         2 devices   1 device    1 device        201809
u2  b2  a4  d7      > 3         2 devices   1 device    1 device        201809
u2  b3  a1  d8      > 3         1 device    2 devices   1 device        201809
u3  b3  a1  d9      3 devices   2 devices   2 devices   1 device        201809
u3  b4  a1  d10     3 devices   1 device    1 device    1 device        201809
u3  b3  a2  d11     3 devices   2 devices   2 devices   1 device        201809

我在列 boxapp 上创建了2个切片器 . 在Clustered柱形图中,对于值,我计算了不同的usr . 在传说中,我想通过设备计算usr的细分 . 桶是1个设备,2个设备,3个设备,多3个设备 .

如果切片器中没有选择:

  • count distinct usr = 3

  • 2 usr - >更多3台设备

  • 1 usr - > 3台设备

如果b1用作过滤器:

  • count distinct usr = 2

  • 1 usr - > 3台设备

  • 1 usr - > 1台设备

如果a1用作过滤器:

  • count distinct usr = 3

  • 3 usr - > 2台设备

如果a1和b1用作过滤器:

  • count distinct usr = 2

  • 1 usr - > 2台设备

  • 1 usr - > 1台设备

我怎样才能做到这一点?

LATER EDIT

我已经将源表更改为与现在完全相同 . 您可以从here下载报告我想要一个动态计数组 . 每次过滤切片器时,usr应该有一个count(设备)组,然后根据这个数量来制作桶:当前过滤器上有多少用户有1个设备,2个设备,3个设备或3个以上的设备 . 在轴上我放了月份列,但它与此示例无关,因为它只有一个值 .

2 回答

  • 0

    正如我上面提到的,这个问题基本上是一个副本:DAX grouping by a measure result

    您需要为您的类别创建一个新表 Buckets

    Bucket
    ------
    1 device
    2 devices
    3 devices
    >3 devices
    

    完成后,将其放在“图例”框中,并对“值”框使用以下度量:

    DynamicBucketingMeasure =
        VAR Summary =
            SUMMARIZE (
                ALLSELECTED ( pbi_box_active_devices_4 ),
                pbi_box_active_devices_4[usr],
                "Devices", DISTINCTCOUNT ( pbi_box_active_devices_4[device] )
            )
        VAR Bucketed =
            ADDCOLUMNS (
                Summary,
                "Bucket", SWITCH (
                    TRUE (),
                    [Devices] > 3, ">3 devices",
                    [Devices] = 1, "1 device",
                    [Devices] & " devices"
                )
            )
        RETURN
            SUMX ( Bucketed, IF ( [Bucket] = SELECTEDVALUE ( Buckets[Bucket] ), 1, 0 ) )
    

    请注意,在这个衡量标准中,我将计数和后续分组分为两个步骤,而不是像在链接问题中那样将它们组合成一个步骤 .

  • 1

    超!当我没有在Axis上使用月份时,它工作正常 . 在较大的数据集上,有更多月份的数据,在所有轴值上,它执行所有数据的总和 . 因此,所有桶组都具有相同的数据 . 我试图将month列添加到group by中:

    VAR Summary =
        SUMMARIZE (
            ALLSELECTED ( pbi_box_active_devices_4 ),
            pbi_box_active_devices_4[usr],
            pbi_box_active_devices_4[month],
            "Devices", DISTINCTCOUNT ( pbi_box_active_devices_4[device] )
        )
    

    但它没有按预期工作 .

相关问题