将当前月份 + 2 和下个月 + 1 和之后的月份相加
Sum Current Month + 2 AND Next Month + 1 and Month After that
我有一个指标需要在 DAX 中为 PowerBI 复制,但我不太确定该怎么做。
基础知识是这样的:
事实Table:机会
维度:创建日期、结束日期
指标是这样的,我只是举个例子,因为我真的不知道怎么解释。
总和:
2 月创建,2 月、3 月、4 月结束日期
3 月创建,3 月、4 月结束
创建于 APR 并于 APR 关闭
table/matrix 中的每个月都会发生这种情况。
似乎我需要一些像
这样的变量
测量=
VAR Month1 = SUM(ClosedOpps) 其中 ClosedDate 在 CurrentMonth 和 CurrentMonth 之间 + 2
VAR Month2 = SUM(CLosedOpps) 其中 ClosedDate 在 CurrentMonth + 1 和 CurrentMonth + 2 之间
VAR Month3 = SUM(ClosedOpps) 其中 ClosedDate = CurrentMonth + 2
Return 月 1 + 月 2 + 月 3
我的理解是,当我将 MonthYear 列拖到视觉对象中时,关闭日期过滤器将是 Table/Matrix 视觉对象
编辑:
这是他们在 Excel 中所做工作的简化副本
所以左边的数据就是事实table。您可以看到 Opps 何时创建,何时关闭。我添加了 Created MonthYear 和 Closed MonthYear。 Pivot 是他们现在在 Excel 中拥有的。顶部(列)的日期是 Created YearMonth,行的日期是 Closed YearMonth。
我需要能够对 I3:K5 中的数字求和,在示例中总计 5500。
更新:
所以我添加了一个建议的日期维度 table,复制它(一个用于开放日期,一个用于关闭日期)我为每个添加了一个列 DateDIM_KEY 这只是一个数字索引.事实上 table 有这些键,并且它们是从相同的日期范围(2013 年到 2030 年)加载的。事实 table 中的 ActualValue 列是我们要求和的列。
这是更新后的事实 table 样本。我直接从这些日期的日期维度中提取了 DateDIM_KEY 值。
这里最好的办法是添加一个自定义列(在编辑查询下),其中包含每月的日期差异。现在您可以在 LeadTimeInMonth
列之后为您的场景进行过滤。如果将字段拖放到视觉对象中,则可以按此列进行筛选。
Date.Month([ClosedDAte])-Date.Month([OpenDate])
我不确定您真正想要评估什么,但如果您确实需要 ClosedDate between CurrentMonth and CurrentMonth + 2
,您可以先评估 ClosedDate
中的月份,然后评估今天的月份,然后在结果后进行过滤。
您需要一个好的日期维度。你需要让它扮演 OpenDate 和 CloseDate 的角色。那里有很多好的约会维度。我喜欢 mine.
假设您将 'OpenDate'[月份] 放在轴标签上。
Opportunity Value = SUM ( 'Opportunity'[Value] )
MyMeasure iterator =
// start of the month on the current row of a pivot/axis label of a chart
VAR CurrentMonthStart = MIN ( 'OpenDate'[Date] )
// End of the month 2 months out
VAR ThreeMonthsOutEnd = EOMONTH ( CurrentMonthStart, 2 )
// This represents one row per month. You could also use a MonthAndYear type field.
// We will walk through the three open months we care about, and in each will sum
// the value for the opportunities opened in that month, with additional filters.
VAR NextThreeOpenMonths =
CALCULATETABLE (
VALUES ( 'OpenDate'[MonthIndex] ),
ALL ( 'OpenDate' ),
DATESBETWEEN ( 'OpenDate'[Date], CurrentMonthStart, ThreeMonthsOutEnd )
)
RETURN
// Iterate each OpenMonth
SUMX (
NextThreeOpenMonths,
// On each step of the iteration, grab the start of the currently iterated month
VAR IterMonthStart = CALCULATE ( MIN ( 'OpenDate'[Date] ) )
RETURN
CALCULATE (
[Opportunity Value],
// There is date context from visuals we want to ignore:
ALLEXCEPT ( 'OpenDate', 'OpenDate'[MonthIndex] ),
// filter CloseDate to be between the start of the currently iterated
// open month and the originally calculated ThreeMonthsOutEnd. The latter
// is static within the scope of the iteration.
DATESBETWEEN ( 'CloseDate'[Date], IterMonthStart, ThreeMonthsOutEnd )
)
)
此外,在编写之前的迭代方法时,我意识到我们可以在单个 setfilter 中完成这项工作:
MyMeasure set =
// MonthIndex is in my date dimension - super useful for arithmetic on dates.
// Read the readme.
VAR C = SELECTEDVALUE ( 'OpenDate'[MonthIndex] ) // want a short name below
// Table literal syntax - two column table, where each parenthesized expression
// forms a row. If it were much more, I'd do something clever with generate, but
// six cases are easy to write by hand.
VAR MonthFilters = {
(C, C),
(C, C+1),
(C, C+2),
(C+1, C+1),
(C+1, C+2),
(C+2, C+2)
}
RETURN
CALCULATE (
[Opportunity Value],
TREATAS ( MonthFilters, 'OpenDate'[MonthIndex], 'CloseDate'[MonthIndex] )
)
我更喜欢后者,但直到写完迭代版本才想到,所以我把两者都留下了。基于集合的性能应该更好。
编辑:一些我忘记的截图:
角色扮演date关系图如下:
这是两种措施的视觉效果:
我有一个指标需要在 DAX 中为 PowerBI 复制,但我不太确定该怎么做。
基础知识是这样的:
事实Table:机会
维度:创建日期、结束日期
指标是这样的,我只是举个例子,因为我真的不知道怎么解释。
总和:
2 月创建,2 月、3 月、4 月结束日期
3 月创建,3 月、4 月结束
创建于 APR 并于 APR 关闭
table/matrix 中的每个月都会发生这种情况。
似乎我需要一些像
这样的变量测量=
VAR Month1 = SUM(ClosedOpps) 其中 ClosedDate 在 CurrentMonth 和 CurrentMonth 之间 + 2
VAR Month2 = SUM(CLosedOpps) 其中 ClosedDate 在 CurrentMonth + 1 和 CurrentMonth + 2 之间
VAR Month3 = SUM(ClosedOpps) 其中 ClosedDate = CurrentMonth + 2
Return 月 1 + 月 2 + 月 3
我的理解是,当我将 MonthYear 列拖到视觉对象中时,关闭日期过滤器将是 Table/Matrix 视觉对象
编辑:
这是他们在 Excel 中所做工作的简化副本
所以左边的数据就是事实table。您可以看到 Opps 何时创建,何时关闭。我添加了 Created MonthYear 和 Closed MonthYear。 Pivot 是他们现在在 Excel 中拥有的。顶部(列)的日期是 Created YearMonth,行的日期是 Closed YearMonth。
我需要能够对 I3:K5 中的数字求和,在示例中总计 5500。
更新:
所以我添加了一个建议的日期维度 table,复制它(一个用于开放日期,一个用于关闭日期)我为每个添加了一个列 DateDIM_KEY 这只是一个数字索引.事实上 table 有这些键,并且它们是从相同的日期范围(2013 年到 2030 年)加载的。事实 table 中的 ActualValue 列是我们要求和的列。
这是更新后的事实 table 样本。我直接从这些日期的日期维度中提取了 DateDIM_KEY 值。
这里最好的办法是添加一个自定义列(在编辑查询下),其中包含每月的日期差异。现在您可以在 LeadTimeInMonth
列之后为您的场景进行过滤。如果将字段拖放到视觉对象中,则可以按此列进行筛选。
Date.Month([ClosedDAte])-Date.Month([OpenDate])
我不确定您真正想要评估什么,但如果您确实需要 ClosedDate between CurrentMonth and CurrentMonth + 2
,您可以先评估 ClosedDate
中的月份,然后评估今天的月份,然后在结果后进行过滤。
您需要一个好的日期维度。你需要让它扮演 OpenDate 和 CloseDate 的角色。那里有很多好的约会维度。我喜欢 mine.
假设您将 'OpenDate'[月份] 放在轴标签上。
Opportunity Value = SUM ( 'Opportunity'[Value] )
MyMeasure iterator =
// start of the month on the current row of a pivot/axis label of a chart
VAR CurrentMonthStart = MIN ( 'OpenDate'[Date] )
// End of the month 2 months out
VAR ThreeMonthsOutEnd = EOMONTH ( CurrentMonthStart, 2 )
// This represents one row per month. You could also use a MonthAndYear type field.
// We will walk through the three open months we care about, and in each will sum
// the value for the opportunities opened in that month, with additional filters.
VAR NextThreeOpenMonths =
CALCULATETABLE (
VALUES ( 'OpenDate'[MonthIndex] ),
ALL ( 'OpenDate' ),
DATESBETWEEN ( 'OpenDate'[Date], CurrentMonthStart, ThreeMonthsOutEnd )
)
RETURN
// Iterate each OpenMonth
SUMX (
NextThreeOpenMonths,
// On each step of the iteration, grab the start of the currently iterated month
VAR IterMonthStart = CALCULATE ( MIN ( 'OpenDate'[Date] ) )
RETURN
CALCULATE (
[Opportunity Value],
// There is date context from visuals we want to ignore:
ALLEXCEPT ( 'OpenDate', 'OpenDate'[MonthIndex] ),
// filter CloseDate to be between the start of the currently iterated
// open month and the originally calculated ThreeMonthsOutEnd. The latter
// is static within the scope of the iteration.
DATESBETWEEN ( 'CloseDate'[Date], IterMonthStart, ThreeMonthsOutEnd )
)
)
此外,在编写之前的迭代方法时,我意识到我们可以在单个 setfilter 中完成这项工作:
MyMeasure set =
// MonthIndex is in my date dimension - super useful for arithmetic on dates.
// Read the readme.
VAR C = SELECTEDVALUE ( 'OpenDate'[MonthIndex] ) // want a short name below
// Table literal syntax - two column table, where each parenthesized expression
// forms a row. If it were much more, I'd do something clever with generate, but
// six cases are easy to write by hand.
VAR MonthFilters = {
(C, C),
(C, C+1),
(C, C+2),
(C+1, C+1),
(C+1, C+2),
(C+2, C+2)
}
RETURN
CALCULATE (
[Opportunity Value],
TREATAS ( MonthFilters, 'OpenDate'[MonthIndex], 'CloseDate'[MonthIndex] )
)
我更喜欢后者,但直到写完迭代版本才想到,所以我把两者都留下了。基于集合的性能应该更好。
编辑:一些我忘记的截图:
角色扮演date关系图如下:
这是两种措施的视觉效果: