2017-09-09 48 views
0

我有一个[公司]列,我在Powerpivot表中有[Billing day]列。 公司可以有几个不同的帐单日期。DAX - 显示计算列中的前1位数

我想在公司名称旁边的数据透视表中显示出现次数最多的帐单日期。 棘手的部分是数字必须出现在[计算列]中,不会将其作为我的数据透视表中的度量值,而是作为列。 我已阅读此类帖子: this onethis one。 我学到了很多,但我仍然无法获得正确的值。

有什么想法? 非常感谢

回答

0

这可能不是最好的方式让你我明白你所要求的,但它是一个方式。我相信它实现了你想要的关于计算列的内容。

如果我开始与此表为表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

然后,如果我选择从它(主页选项卡/数据透视表的下拉箭头按钮/拼合的数据透视表)创建扁平的数据透视表,并做一些事情,像这样:

enter image description here

...和关闭小计和总计,我得到这个:

enter image description here

这是,我相信,你所要求的。

但我认为一个简单的方法可能是这样的:

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

enter image description here

,并使用该表原样,创建扁平的数据透视表直。然后设置数据透视表像这样:

enter image description here

...和关闭小计和总计,得到这个:

enter image description here

...然后你就可以筛选最高一天发生的每家公司:

enter image description here

enter image description here

...得到这个:

enter image description here