2017-09-09 50 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