大多数 efficient/elegant 计算当月用户数的方法
Most efficient/elegant way to calculate Num Users for Current Month
我有以下似乎功能正常但看起来我可能已经做了我惯用的技巧,没有尽可能简单 - 这个措施的优雅版本是什么?
Num Users for Current Month =
VAR
MaxMonth = MONTH(LASTDATE(ALL('Date'[Day Marker])))
VAR
MaxYear = YEAR(LASTDATE(ALL('Date'[Day Marker])))
RETURN
CALCULATE(
[Num Users]
,FILTER(
'Date',
MONTH('Date'[Day Marker]) = MaxMonth
&&
YEAR('Date'[Day Marker]) = MaxYear
) )
使用此代码,您没有选择当前月份。您正在选择日期选择中的最后一个可用月份。
我宁愿用一个额外的字段来扩展我的日期 table:IsCurrentMonth:
IsCurrentMonth =
IF (
YEAR ( Date[Date] ) = YEAR ( TODAY () )
&& MONTH ( Date[Date] ) = MONTH ( TODAY () ),
"Yes",
"No"
)
然后你的测量可以改写为:
CALCULATE([Num Users], Date[IsCurrentMonth]="yes")
我有以下似乎功能正常但看起来我可能已经做了我惯用的技巧,没有尽可能简单 - 这个措施的优雅版本是什么?
Num Users for Current Month =
VAR
MaxMonth = MONTH(LASTDATE(ALL('Date'[Day Marker])))
VAR
MaxYear = YEAR(LASTDATE(ALL('Date'[Day Marker])))
RETURN
CALCULATE(
[Num Users]
,FILTER(
'Date',
MONTH('Date'[Day Marker]) = MaxMonth
&&
YEAR('Date'[Day Marker]) = MaxYear
) )
使用此代码,您没有选择当前月份。您正在选择日期选择中的最后一个可用月份。
我宁愿用一个额外的字段来扩展我的日期 table:IsCurrentMonth:
IsCurrentMonth =
IF (
YEAR ( Date[Date] ) = YEAR ( TODAY () )
&& MONTH ( Date[Date] ) = MONTH ( TODAY () ),
"Yes",
"No"
)
然后你的测量可以改写为:
CALCULATE([Num Users], Date[IsCurrentMonth]="yes")