powerbi, 求前12个月平均数

平均数 =
	VAR CurrentYearMonth = '按月汇总表'[年月]
	VAR CurrentYear = INT(CurrentYearMonth / 100)
	VAR CurrentMonth = MOD(CurrentYearMonth, 100)
	VAR StartYearMonth =IF(        
		CurrentMonth <= 12,(CurrentYear - 1) * 100 + CurrentMonth,        
		CurrentYear * 100 + (CurrentMonth - 12))
	RETURN
		CALCULATE(AVERAGE('按月汇总表'[总数量]),
						FILTER(ALL('按月汇总表'),'按月汇总表'[年月] > StartYearMonth         
						&& '按月汇总表'[年月] <= CurrentYearMonth     
					)

  

posted @ 2025-07-15 11:07  CrossPython  阅读(8)  评论(0)    收藏  举报