首页 文章

基于计算字段的Power BI / PowerPivot模型中的动态分组

提问于
浏览
0

EDIT: I'm open for any suggestion, not only Power Pivot, but also Power Query (M functions) or Power BI or whatever could work. Thanks.

我们正在尝试在Excel / Power BI中创建模型(使用Power Query或Power Pivot或任何可行的方法),以便通过其最佳产品(基于排名系统)对客户进行分类 .

我们应用的第一种方法是按最低排名(或每个最佳产品品牌)计算客户数 . (灵感来自博客https://stackoverflow.com/questions/15742186/powerpivot-dax-dynamic-ranking-per-group-min-per-group

在我们完成的步骤下面: - 在PowerPivot模型中,我们创建了 ClassificationCustomers 表,如下面的示例中所示 .

  • 在同一模型中,我们添加了一个带有以下公式的 calculated column 来获取 minimum rank per customer .
=MINX (
FILTER ( ALLSELECTED ( Customers ); [Customer_ID] = EARLIEST ( [Customer_ID] ) );
[Ranking]
)
  • 在Excel中的数据透视表中,我们将计算列放在行中 .

  • 然后,我们在数据透视表值中使用了 Count distinct aggregation of the customers . 这给了我第一个期望的结果 . (下面的例子是Pivot_Table.Selection1)

现在,问题出现在我们想要 add more analysis axis 的时候 . 例如,除了产品品牌之外,我们希望将产品类型设置为列,并且我们希望我们的度量为 recalculated every time I add/delete an axis. 换句话说,我们希望每个最佳产品和每个产品类型具有不同的客户数量 . 另外,我们要 the second attribute (axis) to be variable and the grouping or the distinct count per group to be dynamic.

Example

假设我们的模型中有表格分类和客户:

enter image description here

enter image description here

在我们尝试的第一种方法中,我们得到了下表:Pivot_Table.Selection1:

enter image description here

现在,当我们添加分析轴时,我们希望得到以下示例:Pivot_Table.Selection2:

enter image description here

但我们有这个:

enter image description here

如您所见,集团“梅赛德斯”和“雷诺”应该有一个客户,因为根据产品类型,客户A的顶级卡车是雷诺,其顶级车型是“梅赛德斯” . 但是,在数据透视表中,梅赛德斯组显示为卡车(在我们的数据集中甚至不存在) .

enter image description here

任何帮助或输入将受到高度赞赏 .

非常感谢您的任何回复 .

此致,Rami&Frantz .

1 回答

  • 0

    最后,我认为我理解了您的问题,客户可以拥有不同的Product_Brand值,您只想计算其排名最低的Product_Brand .

    在这种情况下,这是一个可能的解决方案:

    Customer 表中创建名为 Minimum Rank 的计算列 .

    =
    CALCULATE (
        MIN ( [Ranking] );
        FILTER ( Customer; [Customer_ID] = EARLIER ( Customer[Customer_ID] ) )
    )
    

    然后创建一个度量,让我们说 Customer ID Distinct Count 来计算Rank等于该客户的最小值的那些行 .

    Customer ID Distinct Count :=
    CALCULATE (
        DISTINCTCOUNT ( Customer[Customer_ID] );
        FILTER ( Customer; [Ranking] = [Minimum Rank] )
    )
    

    你会得到这样的东西:

    enter image description here

    enter image description here

    如果这有帮助,请告诉我 .

相关问题