2015-10-16 97 views
0

我在通過PowerPivot給出正確數字的計算函數時遇到問題。假設有以下信息。DAX計算多個標準問題

RepairsTable 

Repair ID Location Amount Date 
1 West 50 Aug 
2 East 60 Aug 
3 West 40 Sep 
4 East 30 Sep 
5 West 1000 Sep 

MilesTable 

Location Miles Date Total Amt Repairs 
West 100 Sep 
East 100 Aug 

在數表中的總金額是維修PowerPivot中的計算列,我想展示基於位置&從表修理修理日期的總金額$。

我已經使用以下公式:

=CALCULATE(SUM(RepairsTable[Amount]),FILTER(RepairsTable,RepairsTable[Date]=MilesTable[Date])) 

=CALCULATE(SUM(RepairsTable[Amount]),FILTER(RepairsTable,RepairsTable[Location]=MilesTable[Location])) 

除了:

=CALCULATE(SUM(RepairsTable[Amount]),FILTER(RepairsTable,RepairsTable[Date]=MilesTable[Date]&&RepairsTable[Location]=MilesTable[Location])) 

=CALCULATE(SUM(RepairsTable[Amount]),FILTER(RepairsTable,RepairsTable[Date]=MilesTable[Date]),FILTER(RepairsTable,RepairsTable[Location]=MilesTable[Location])) 

我不能爲我的生活似乎拿出了Total Amt Repairs計算列中的正確值。我要尋找的值是:

1040 for West/Sep 
60 for East/Aug 

我能做到這一點就好了,在電子表格中的SUMIFS功能,但我不能讓它在的PowerPivot工作。

回答

0

所以,這裏要介紹幾件事情。

  1. 如果問題在別處解決,爲什麼要更換工具?
  2. 爲什麼此聚合需要在計算列中?您在此查看的聚合類型通常是通過度量值在數據透視表中執行的,而不是在計算列中執行。
  3. 如果瞭解上述內容,您仍然相信在模型的計算列中執行此操作是正確的解決方案,那麼您的第三和第四個度量都適用於我的樣本數據,而表格之間沒有關係,與每個表[位置]之間的關係或每個表[日期]之間的關係。

除此之外,你想要什麼是最好的配方如下:

=CALCULATE(
    SUM(RepairsTable[Amount]) 
    ,RepairsTable[Date] = EARLIER(MilesTable[Date]) 
    ,RepairsTable[Location] = EARLIER(MilesTable[Location]) 
) 

我毫不猶豫地建議它,雖然,因爲這等同於你的第4個定義有兩個過濾器,只是更乾淨表達。

真實數據與本示例有什麼不同?