1

我需要创建显示累积不同计数的数据透视图(为了非常方便的过滤和效率,它应该是数据透视图,但任何等价物都可以做)。例如我有一个数据集:

Month ¦ Drink brand ¦ Drink type
--------------------------------
1     ¦ Abc         ¦ Water
1     ¦ Def         ¦ Soft
1     ¦ Abc         ¦ Water
1     ¦ Ghi         ¦ Soft
1     ¦ Xyz         ¦ Water
2     ¦ Abc         ¦ Water
2     ¦ Abc         ¦ Water
2     ¦ Jkl         ¦ Soft
2     ¦ Opq         ¦ Soft
2     ¦ Abc         ¦ Water

从这里我想得到一个图表:

           ¦
Drink      ¦
type       ¦            S
cumulative ¦            []
unique     ¦ W  S    W  []
count      ¦ [] []   [] []
           ¦_[]_[]___[]_[]_
               1       2
                 Month

我尝试在值字段设置中使用“汇总值”->“不同计数”和“显示值为”->“运行总计”,但运行选项似乎不了解不同计数背后的理念,只是添加每个月的不同计数。

4

1 回答 1

1

累计计数

我已经设法使用 power pivot 和 DAX 解决了这个特殊问题。

在此之后: http ://www.daxpatterns.com/cumulative-total/ 以及提供的累积总计示例

Cumulative Quantity :=
CALCULATE (
    SUM ( Transactions[Quantity] ),
    FILTER (
        ALL ( 'Date'[Date] ),
        'Date'[Date] <= MAX ( 'Date'[Date] )
    )
)

我创建了两个新的计算字段(“POWERPIVOT”->“Calculated Fields”),“Water_cumulative_count”:

=CALCULATE (
    DISTINCTCOUNT( Range[Drink brand] ),
    FILTER (
        ALL ( Range[Month] ),
        Range[Month] <= MAX ( Range[Month] )
    ),
    FILTER (
        ALL ( Range[Drink type] ),
        Range[Drink type] = "Water"
    )
)

和类比的“Soft_cumulative_count”。

然后我简单地将这些新字段添加到数据透视表中。

虽然它解决了这个特殊问题,但我对这个解决方案的低可扩展性不满意。如果我有许多“饮料类型”,那么创建尽可能多的新计算字段将非常无效。我想知道是否有更好的方法来使用 DAX 来解决它。也许......但我是这个主题的 1 天新手。

于 2016-01-19T13:18:23.350 回答