DAX - 显示计算列中的前1个计数

时间:2017-09-09 17:01:20

标签: pivot calculated-columns dax frequency-distribution

我有一个[公司]专栏,我在powerpivot表中有一个[结算日]列。 公司可以有几个不同的结算日。

我想在公司名称旁边的数据透视表中显示出现次数最多的结算日。 棘手的部分是数字必须出现在[计算列]中,不会在我的数据透视表中作为度量,而是作为列。 我查看过以下帖子: this onethis one。 我学到了很多,但我仍然无法得到正确的数值。

有什么想法吗? 非常感谢

1 个答案:

答案 0 :(得分:0)

这可能不是最佳方式,可以让您了解我所理解的内容,但它是 方式。我相信它可以达到你想要的计算列。

如果我从表1开始,如表1所示:

enter image description here

然后我使用以下代码添加一列:MaxByDate = COUNTX(FILTER(FILTER(Table1,Table1[Company]=EARLIER(Table1[Company])),Table1[Billing Day]=EARLIER(Table1[Billing Day])),Table1[Billing Day])

我使用此代码添加了另一列:MaxOverall = MAXX(FILTER(Table1,Table1[Company]=EARLIER(Table1[Company])),COUNTX(FILTER(FILTER(Table1,Table1[Company]=EARLIER(Table1[Company])),Table1[Billing Day]=EARLIER(Table1[Billing Day])),Table1[Billing Day]))

然后我使用以下代码添加最后一列:DateOfMaxOverall = FORMAT(SUMX(FILTER(FILTER(Table1,[Company]=EARLIER([Company])),[MaxByDate]=[MaxOverall]),[Billing Day])/COUNTX(FILTER(FILTER(Table1,[Company]=EARLIER([Company])),[MaxByDate]=[MaxOverall]),[Billing Day]),"m/d/yyyy")

我得到这张表:

enter image description here

然后,如果我选择从它创建一个Flattened PivotTable(Home tab / PivotTable下拉箭头按钮/ Flattened PivotTable),并设置如下:

enter image description here

...并关闭小计和总计,我明白了:

enter image description here

我相信,你要求的是什么。

但我认为更简单的方法可能就是这样:

从第一个表开始(表1):

enter image description here

并且,按原样使用该表,直接创建一个Flattened PivotTable。然后像这样设置数据透视表:

enter image description here

...并关闭小计和总计,以获得此结果:

enter image description here

...然后您可以过滤每家公司的最大发生日期:

enter image description here

enter image description here

......得到这个:

enter image description here

相关问题