我在spotfire里有个公式
Sum(sales)/10000*28
但这28只是(EOMONTH(X,-1)-EOMONTH(X,-2))
X只不过是31Mar2015
所以这就像当当前月份是三月,它就像是二月末-一月末,我必须填充所有月份,就像当周期末是四月,然后我们计算三月末到二月末之间的天数。有谁能帮忙吗?
发布于 2015-06-06 00:23:55
如果您所需要的只是增量值,我们可以简化此过程。如果我错了,请纠正我,但是取一个月的月末减去另一个月的EOM实际上就是第一个值的月份中的天数。
例如,输入3月份,然后我将查看2月份,看看是28天(除非是29)。不需要EOMONTH-EOMONTH计算,因为这些日历值在闰年之外是静态的。
下面是一个spotfire表达式,它应该提供您需要的值。我还包含了一些处理闰年的模逻辑(如果当前月份是三月,则检查是否为闰年)。如果是,则result = 29,否则为28。)
Case
when Month(DateTimeNow()) = 1 then 31
when Month(DateTimeNow()) = 2 then 31
when Month(DateTimeNow()) = 3 and Mod(Year(DateTimeNow()),4)=0
and (Mod(Year(DateTimeNow()),100)!=0 or Mod(Year(DateTimeNow()),400)=0) then 29
when Month(DateTimeNow()) = 3 then 28
when Month(DateTimeNow()) = 4 then 31
when Month(DateTimeNow()) = 5 then 30
when Month(DateTimeNow()) = 6 then 31
when Month(DateTimeNow()) = 7 then 30
when Month(DateTimeNow()) = 8 then 31
when Month(DateTimeNow()) = 9 then 31
when Month(DateTimeNow()) = 10 then 30
when Month(DateTimeNow()) = 11 then 31
when Month(DateTimeNow()) = 12 then 30
end如果您实际上不需要当前月份并且有一个输入列,则可以替换Month(DateTimeNow())。此外,您还可以将结果计算列添加到上面的内容中,或者只将上面的内容作为公式引用的计算列插入:Sum([sales])/10000*[calc_col]
让我知道这是否对你有效,如果你有任何问题。
供参考:
没有凌乱的Spotfire代码的闰年逻辑:
if( 0 == year % 4 and (0 != year % 100 or 0 == year % 400) )
{
# Then year is a leap year.
}从this perl code修改。
Days of Month reference
编辑:
根据@Niko,如果我们不使用闰年逻辑,我们可以稍微清理一下代码。这真的取决于这个解决方案的闰年逻辑的必要性。
Case Month(DateTimeNow())
when 1 then 31
when 2 then 31
when 3 then 28
when 4 then 31
when 5 then 30
when 6 then 31
when 7 then 30
when 8 then 31
when 9 then 31
when 10 then 30
when 11 then 31
when 12 then 30
end发布于 2015-06-06 13:55:28
我每个月的第一天休息,加上一个月,然后休息一天。
DateAdd(‘天’,-1,日期(年(DateTimeNow()),月(DateAdd(‘月’,1,DateTimeNow(),1)
DateTimeNow()可以替换为日期列。
一旦您有了给定日期的月份的最后一天,就可以提取日期(此处为/above表达式/)
发布于 2016-04-27 02:29:09
在遇到类似的问题后又回到了这个问题上。我把@clesiemo3的答案缩小了一点:
CASE
WHEN Month([Date]) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN Month([Date]) IN (4, 6, 9, 11) THEN 30
WHEN (Month([Date])=2) AND (Mod(Year([Date]),4)=0)
AND ((Mod(Year([Date]),100)!=0) or (Mod(Year([Date]),400)=0)) THEN 29
ELSE 28
ENDhttps://stackoverflow.com/questions/30670035
复制相似问题