我必须计算一段时间内打开的门票。我的桌子是这样的结构
id问题 | 创作 | 状态更改日期 | 状态 |
---|---|---|---|
100 | 2024/06/01 | 2024/06/29 | 已关闭 |
200 | 2024/06/10 | 2024/06/29 | 已开通 |
200 | 2024/06/01 | 2024/06/30 | 准备好 |
200 | 2024/06/10 | 2024/03/07 | 已关闭 |
300 | 2024/08/01 | 2024/08/01 | 已开通 |
300 | 2024/08/01 | 2024/09/03 | 准备好 |
我尝试用不同的方式解决,但我无法实现
第一
VAR _Month = SELECTEDVALUE(DimCalendarIssues[Month])
VAR _Year = SELECTEDVALUE(DimCalendarIssues[Year])
VAR _FinMes = EOMONTH(DATE(_Year, _Month, 1), 0)
RETURN
CALCULATE(
DISTINCTCOUNT(Fac_Jira[IdIssue]),
FILTER(
Fac_Jira,
Fac_Jira[StatusCreatedDate] >= DATE(2024,06,01)
&& Fac_Jira[StatusCreatedDate] <= _FinMes
&& NOT(Fac_Jira[IdStatus] IN {[Closed], [Finished], [Cancelled]})
&& Fac_Jira[StatusCreatedDate] =
CALCULATE(
MAX(Fac_Jira[StatusCreatedDate]),
Fac_Jira,
Fac_Jira[IdIssue] = EARLIER(Fac_Jira[IdIssue])
&& Fac_Jira[StatusCreatedDate] >= DATE(2024,06,01)
&& Fac_Jira[StatusCreatedDate] <= _FinMes
)
)
)
第二次使用中间表
VAR _Month = SELECTEDVALUE(DimCalendarIssues[Month])
VAR _Year = SELECTEDVALUE(DimCalendarIssues[Year])
VAR _FinMes = EOMONTH(DATE(_Year, _Month, 1), 0)
VAR _lastStates =
SUMMARIZE(
FILTER(
Fac_Jira,
Fac_Jira[CreationDate] > DATE(2024, 06, 01)
),
Fac_Jira[IdIssue],
"LastDateState", MAX(Fac_Jira[StatusCreatedDate]),
"LastState",
CALCULATE(
MAX(Fac_Jira[IdStatus]),
FILTER(
Fac_Jira,
Fac_Jira[IdIssue] = EARLIER(Fac_Jira[IdIssue]) &&
Fac_Jira[StatusCreatedDate] = MAX(Fac_Jira[StatusCreatedDate])
)
)
)
VAR _Filtered =
FILTER(
_lastStates,
[LastDateState] <= _FinMes &&
NOT([LastDateState] IN {[Opened], [Finished], [Cancelled]})
)
RETURN
COUNTROWS(_Filtered)
两者都效果不佳。
感谢您的帮助。
根据您的方法,为什么不尝试以下方法来计算特定日期范围内已打开的工单。
CountOpenedTickets =
VAR StartDate = DATE(2024, 6, 1)
VAR EndDate = EOMONTH(StartDate, 0)
RETURN
CALCULATE(
DISTINCTCOUNT(Fac_Jira[IdIssue]),
FILTER(
Fac_Jira,
Fac_Jira[CreationDate] <= EndDate && // Ticket must be created before or on EndDate
Fac_Jira[StatusChangedDate] > StartDate && // Ticket must still be opened after StartDate
Fac_Jira[Status] IN {"Opened", "prepared"} // Only count tickets that are opened
)
)