DAX度量将每月应用相同的值

时间:2019-10-24 14:38:39

标签: dax

我正在尝试合并我使用多种度量方法得出的年终预测。我遇到了一个问题,我试图使9月份的价格在所有月份都显示出来。

注意这不是完整的代码。

这非常适合我的CompMoCI变量。我无法将其用于HisCompMoAvg变量。

SAIFI YEP = 
var CurYr = YEAR(TODAY())
var CurMo = MONTH(TODAY())
var Yr1Back = CurYr - 1
var Yr2Back = CurYr - 2
var Yr3Back = CurYr - 3
var Yr4Back = CurYr - 4
var Yr5Back = CurYr - 5
var CurYrCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = CurYr)
var CompMoCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = CurYr, 'Date Table'[Monthnumber] = (CurMo-1), ALLSELECTED(Outages), ALLSELECTED('Date Table'), ALLSELECTED(Customers))
var Yr1BackCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = Yr1Back)
var Yr2BackCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = Yr2Back)
var Yr3BackCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = Yr3Back)
var Yr4BackCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = Yr4Back)
var Yr5BackCI = CALCULATE(TOTALYTD([CI by Data Naming Convention], 'Date Table'[Date]), 'Year'[Year] = Yr5Back)
var HisTotal = CALCULATE(Yr1BackCI + Yr2BackCI + Yr3BackCI + Yr4BackCI + Yr5BackCI, ALLSELECTED(Outages), ALLSELECTED('Date Table'[Date]), ALLSELECTED(Customers))
var HisTotalAvg = CALCULATE(HisTotal, ALLSELECTED(Outages), ALLSELECTED('Date Table'), ALLSELECTED(Customers))/5
var AvgMoAhead = if(MAX('Date Table'[Monthnumber]) >= CurMo, HisTotalAvg, 0)
var HisCompMoAvg = CALCULATE(HisTotalAvg, 'Date Table'[Monthnumber] = 9, ALLSELECTED(Outages), ALLSELECTED('Date Table'), ALLSELECTED(Customers))
var test = HisCompMoAvg
return test

1 个答案:

答案 0 :(得分:0)

这个问题应该改写。我们只能猜测您想要什么。

+-------+-------+-----------------+
| month | sales | expected result |
+-------+-------+-----------------+
| Jan   |    13 |             130 |
| Feb   |    32 |             130 |
| Mar   |    45 |             130 |
| Apr   |    61 |             130 |
| May   |    77 |             130 |
| Jun   |    85 |             130 |
| Jul   |    98 |             130 |
| Aug   |   109 |             130 |
| Sep*  |   130 |             130 |
| Oct   |   151 |             130 |
| Nov   |   178 |             130 |
| Dec   |   196 |             130 |
+-------+-------+-----------------+

问题。如何构造一个DAX度量来显示所有月份的9月销售额?

!Sales = SUM('Table'[sales])

YourMeasure = CALCULATE([!Sales], ALL('Table'[month]), 'Table'[month]="Sep")

了解函数ALL,CALCULATE和KEEPFILTERS。

DAX Calculate function with and without FILTER

Difference between CALCULATE(m, x=red) vs CALCULATE(m, KEEPFILTERS(x=red))

DAX Total by category displayed for single category